Question: WRITE IN C++ : The file UndirectGraph.cpp contains a definition of an undirected graph. Use this file (graph) to create a program which will calculate

WRITE IN C++ :

The file UndirectGraph.cpp contains a definition of an undirected graph. Use this file (graph) to create a program which will calculate the weight sum of all the edges in the minimum spanning tree, formed using the Kruskal algorithm. Print the minimum spanning tree. Since it is an undirected graph, the value of each edge has to be calculated only once (it doesn't have to be calculated in the both directions).

The file UndirectGraph.cpp :

#include using namespace std; #include "GRAPH.h"

void main() { char vertex[] = {'S', 'R', 'G', 'B', 'O', 'T', 'V'}; int numVertices = sizeof(vertex)/sizeof(char); GRAPH g(vertex, numVertices);

g.setEdge('S', 'R', 10); g.setEdge('S', 'T', 120); g.setEdge('R', 'O', 60); g.setEdge('R', 'T', 90); g.setEdge('R', 'V', 120); g.setEdge('G', 'B', 30); g.setEdge('O', 'T', 20); g.setEdge('T', 'V', 30);

cout << " The graph g:" << endl; g.print(); cout << endl;

Note: calculate the sum of all the edges in both directions (i.e. from and to each vertex, where there is an edge), and then divide the resulting sum by two.

Example output:

The graph g:

S: R(10) T(120)

R: S(10) O(60) T(90) V(120)

G: B(30)

B: G(30)

O: R(60) T(20)

T: S(120) R(90) O(20) V(30)

V: R(120) T(30)

The minimum spanning tree according Kruskal algorithm is:

S: R(10)

R: S(10) O(60)

G: B(30)

B: G(30)

O: R(60) T(20)

T: O(20) V(30)

V: T(30)

The weight sum of all the edges in the minimum spanning tree is 150.

Press any key to continue ..

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!