Kruskal's Algorithm
Explore Kruskal's algorithm for building minimum spanning trees from connected weighted graphs. Understand its step-by-step edge selection and the proof behind its greedy approach to ensure minimum total weight. Learn how the algorithm works on both connected and disconnected graphs.
We'll cover the following...
In this lesson, we’ll study Kruskal’s algorithm, which makes use of a surprisingly straightforward strategy to assemble a minimum spanning tree.
Computing MSTs with Kruskal’s algorithm
The input to Kruskal’s algorithm is a connected, weighted, undirected graph . The algorithm iteratively builds up an acyclic graph with . In the beginning, is empty. The edges will be added until is a spanning tree of .
First, we’ll sort all edges of by their weight in increasing order. Next, we’ll inspect each edge in this order, one by one. If and are in different connected components of , we’ll add to . Otherwise, we’ll skip , as it would introduce a cycle in .
We’ll continue this strategy until we have processed all edges, at which point is a spanning tree of .
Let’s illustrate the algorithm on the example graph from the previous lesson:
The edge with the lowest weight is with weight . We’ll add it as the first edge to our subgraph (marked in blue below).
The next edges are of weight and ...