Minimum Spanning Tree
Minimum Spanning Tree
Given a connected and undirected graph, a spanning tree of that graph is a sub-
graph that is a tree and connects all the vertices together. A single graph can have
many different spanning trees. 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.
The weight of a spanning tree is the sum of weights given to each edge of the
spanning tree.
Below are the steps for finding MST using Kruskal’s algorithm.
Step #1
Step #2
The algorithm is a Greedy Algorithm. The Greedy Choice is to pick the smallest
weight edge that does not cause a cycle in the MST constructed so far. Let us
understand it with an example: Consider the below input graph.
The graph contains 9 vertices and 14 edges. So, the minimum spanning tree
formed will be having (9 – 1) = 8 edges.
After sorting:
6. Pick edge 8-6: Since including this edge results in the cycle, discard it.
7. Pick edge 2-3: No cycle is formed, include it.
8. Pick edge 7-8: Since including this edge results in the cycle, discard it.
9. Pick edge 0-7: No cycle is formed, include it.
10. Pick edge 1-2: Since including this edge results in the cycle, discard it.
11. Pick edge 3-4: No cycle is formed, include it.
Since the number of edges included equals (V – 1), the algorithm stops here.