Kruskal's Algorithm
Learn to compute minimum spanning trees using Kruskal's algorithm.
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:
Get hands-on with 1400+ tech skills courses.