Question
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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started