Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data Structures: Write a method that is part of a class for a graph implemented as an adjacency matrix. The method returns the sum of

Data Structures:

Write a method that is part of a class for a graph implemented as an adjacency matrix. The method returns the sum of weights for a minimum spanning tree using Kruskal's algorithm. The graph is an undirected graph.

First line of input is the number of preceding lines or edges (n). And next n lines represents from_edge, to_edge and weight.

The output from the method should be the sum of weights of the minimum spanning tree.

Sample Input:

6 1 2 10 1 3 20 1 4 15 2 4 40 2 3 50 3 4 5 

Sample Output:

30

#include #include

class My_Graph { const static int MAXNUMVERTICES = 100; int theGraph[MAXNUMVERTICES][MAXNUMVERTICES]; public:

void insertEdge(int to, int from, int weight) { theGraph[to][from] = weight; theGraph[from][to] = weight; }

int sumOfMST() { //your code here

} };

int main() { My_Graph *theGraph = new My_Graph(); int numEdges, inVert, outVert, wt; std::cin >> numEdges; for (int i=0; i> inVert; std::cin >> outVert; std::cin >> wt; theGraph->insertEdge(inVert, outVert, wt); } std::cout<sumOfMST(); }

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

Students also viewed these Databases questions

Question

ensure that your advertising is legal, decent, honest and truthful.

Answered: 1 week ago