Analyze the complexity your algorithms
graph one:
20
2,4,7
4,5,10
16,7,6
7,10,5
7,13,10
13,14,8
1,9,20
8,4,15
12
1,9,3
3,10,1.5
4,9,3.2
6,7,5.5
graph three
1,5,2.4
7,4,8.3
8,2,8.2
2,3,1.5
15
20
6,9,1.2
6,15,9.8
15,12,3.1
4,5,1.2
11,10,1.2
10,8,5.1
This solution was written by a subject matter expert. It's designed to help students like you learn core concepts.
cout<<endl;
}
}
void DFS(int v,int *visited,double **adj_mat)
{
visited[v] = 1;
for(int i = 0; i < V; i++)
{
if(!visited[i] && adj_mat[v][i]!=0 )
DFS(i,visited,adj_mat);
}
}
int main()
{
for(int i = 0; i < V; i++)
{
adj_mat[i] = new double[V];
}
for(int i = 0; i < V; i++)
{
for(int j = 0; j < V; j++)
adj_mat[i][j] = 0;
}
//cout<<u<<"\t"<<v<<endl;
if(myfile.is_open())
{
while(myfile >> u >> ch >> v >> ch >>
w)
{
//cout<<u<<"\t"<<v<<"\t"<<w<<"\t"<<endl;
adj_mat[u-1][v-1] = w;
}
}
cout<<"Adjaceny matrix is "<<endl;
print_adj_mat(adj_mat);
int *visited = new int[V];
int flag = 0;
//here we are using DFS to check graph is connected or not.If all the
nodes are visited from given node then it's connected
DFS(0,visited,adj_mat);
V=20 E=25
Adjaceny matrix is
0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Not Connected Graph
Process returned 0 (0x0) execution time : 0.122 s
Press any key to continue