这是一个C ++程序,其中我们为给定的边缘'e'生成无向随机图。该算法基本上在大型网络上实现,该算法的时间复杂度为O(log(n))。
算法Begin
Function GenerateRandomGraphs(), has ‘e’ as the number edges in the argument list.
Initialize i = 0
while(i
edge[i][0] = rand()%N+1
edge[i][1] = rand()%N+1
Increment I;
For i = 0 to N-1
Initialize count = 0
For j = 0 to e-1
if(edge[j][0] == i+1)
Print edge[j][1]
Increase count
else if(edge[j][1] == i+1)
Print edge[j][0]
Increase count
else if(j == e-1 && count == 0)
Print Isolated Vertex
End
示例#include
#include
#define N 10
using namespace std;
void GenerateRandomGraphs(int e) {
int i, j, edge[e][2], count;
i = 0;
//生