spanning tree

17 Comments

C++ programs to implement the Kruskal’s algorithm to generate a minimum cost spanning tree

/* Write C++ programs to implement the Kruskal’s algorithm to generate a minimum cost spanning tree */ #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int cost[10][10],i,j,k,n,m,c,visit,visited[10],l,v,count,count1,vst,p;   main() { int dup1,dup2; cout<<"enter no of vertices"; cin >> n; cout <<"enter no of edges"; cin >>m; cout <<"EDGE Cost"; for(k=1;k<=m;k++) { cin >>i >>j >>c; cost[i][j]=c; cost[j][i]=c; […]

28 Comments

C++ programs to implement the Prim’s algorithm to generate a minimum cost spanning tree

/* Write C++ programs to implement the Prim’s algorithm to generate a minimum cost spanning tree */ #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int cost[10][10],i,j,k,n,stk[10],top,v,visit[10],visited[10],u;   main() { int m,c; cout <<"enterno of vertices"; cin >> n; cout <<"ente no of edges"; cin >> m; cout <<"\nEDGES Cost\n"; for(k=1;k<=m;k++) { cin >>i>>j>>c; cost[i][j]=c; } for(i=1;i<=n;i++) […]