Minimum Spanning Trees
Algorithms · Advanced Placement
Minimum Spanning Trees: the big picture
A minimum spanning tree of a connected weighted undirected graph is a subset of edges connecting all vertices with minimum total weight, and it contains exactly one fewer edge than the vertex count. Both standard algorithms are greedy and both rest on the cut property: for any partition of the vertices into two sets, the minimum-weight edge crossing the partition belongs to some minimum spanning tree, which is proved by an exchange argument. Kruskal's algorithm sorts all edges by weight and adds each edge whose endpoints are not already connected, using a disjoint-set structure for the connectivity test, giving a cost dominated by the sort. Prim's algorithm grows a single tree from an arbitrary start vertex, repeatedly adding the minimum-weight edge from the tree to a vertex outside it, using a priority queue keyed by that minimum edge weight, giving a cost that depends on the queue implementation and is better for dense graphs. Both produce a tree of the same total weight, though possibly different trees when weights tie. Minimum spanning trees are used in network design, in clustering by removing the heaviest edges, and as a subroutine in approximation algorithms for the travelling salesman problem.
The Cut Property, Kruskal's & Prim's Algorithms
A minimum spanning tree connects every vertex with the least total weight, and both standard algorithms are greedy for the same reason: the cut property. Split the vertices any way you like, and the lightest edge crossing that split belongs to some minimum spanning tree. Kruskal sorts all edges and adds any that does not create a cycle, using union-find for the test. Prim grows one tree outward with a priority queue. Kruskal suits sparse graphs where the sort dominates; Prim suits dense ones.
{{illustration:algos-l15-f1}}
{{illustration:algos-l15-f2}}
Key relations
- Minimum spanning tree bounds. |T| = V − 1 ; T_Kruskal = O(Elog E) ; T_Prim = O(E + Vlog V)
MST Applications, Clustering & Approximation Bounds
The minimum spanning tree is a surprisingly versatile subroutine. Remove its k−1 heaviest edges and you have k clusters, which is exactly single-linkage clustering and maximises the minimum separation between clusters. Double the tree's edges and you get a closed walk, which gives a two-approximation for the travelling salesman problem when the distances satisfy the triangle inequality. And the spanning tree protocol in Ethernet uses the same idea to break loops in a switched network without any central coordination.
{{illustration:algos-l15-f3}}
{{illustration:algos-l15-f4}}
Key relations
- MST applications and their bounds. w(T) ≤ w(OPT tour) ≤ 2w(T) ; cut k−1 heaviest ⇒ k max−spacing clusters