Program 1
Program 1
Design and implement C/C++ Program to find Minimum Cost Spanning Tree of a given
connected undirected graph using Kruskal's algorithm.
Sol:
A minimum spanning tree (MST) or minimum weight spanning tree for a weighted,
connected, undirected graph is a spanning tree with a weight less than or equal to the weight
of every other spanning tree.
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int n = 4; // Number of nodes
vector<vector<int>> edges = {
{0, 1, 10}, {0, 2, 6}, {0, 3, 5}, {1, 3, 15}, {2, 3, 4}
};
cout << "Minimum Cost of Spanning Tree: " << kruskal(n, edges) << endl;
return 0;
}