Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions