A spanning tree of a connected graph G = (V, E) is a subgraph T \subseteq G such that:
Key facts: - Every spanning tree has exactly |V|-1 edges. - There is exactly one path between any two vertices in T. - A connected graph can have many different spanning trees.
\text{connected} + \text{acyclic} + |V|-1 \text{ edges} \;\Longleftrightarrow\; \text{spanning tree}
Any two of these three properties implies the third.
Given a connected graph G=(V, E) with real valued edge weights c_e, an MST is a spanning tree T\subseteq E whose sum of edge weights is minimized.
Foundational problem — one of the oldest and most well-studied in graph theory (Boruvka, 1926)
Greedy paradigm — all three classical algorithms (Kruskal’s, Prim’s, Boruvka’s) are greedy
Building block — used as a subroutine in approximation algorithms for harder problems (TSP, Steiner tree)
Applications everywhere — networks, clustering, image analysis, error-correcting codes
Network Design (STP) — Ethernet switches use the Spanning Tree Protocol (IEEE 802.1D) to compute an MST of the network topology, preventing broadcast storms while maintaining connectivity.
Clustering — Single-linkage clustering computes an MST of data points; removing the k-1 heaviest edges gives k clusters. Used in phylogenetics, customer segmentation, image segmentation.
Approximation Algorithms — Metric TSP uses MST for a 2-approximation; Steiner tree uses MST on terminal pairs for a 2-approximation; facility location via MST dual fitting.
Other uses — LDPC error-correcting codes, medical image registration (Renyi entropy), bioinformatics (protein sequence alignment), RSTP for mesh networks.
In a graph G=(V, E) a cut is a bipartition of V into sets S, V-S for some S\subseteq V. We show it by (S,V-S).
An edge e=\{u,v\} crosses the cut (S, V-S) if exactly one of u,v is in S.
Let S be any subset of nodes (called a cut), and let e = \{u, v\} be the minimum cost edge crossing (S, V-S). Then every MST contains e.
Proof. Proof. Suppose e does not belong to some MST T^*.
Let C be any cycle in G, and let f be the maximum cost edge in C. Then the MST T^* does not contain f.
Proof. Proof. Suppose f belongs to T^*.
Algorithm:
Step 0 / 9 — click ▶
Kruskal’s algorithm needs to check: are u and v already in the same connected component?
find(u) — which component does u belong to?union(u, v) — merge the components of u and v.Union-Find (a.k.a. Disjoint Set Union, DSU) handles both in nearly constant time.
makeset(x): Create a new set containing just x.
find(x): Return the representative of the set containing x.
union(x, y): Merge the sets containing x and y.
| Operation | Without optimization | With optimizations |
|---|---|---|
makeset |
O(1) | O(1) |
find |
O(\text{depth}) | O(\alpha(n)) |
union |
O(\text{depth}) | O(\alpha(n)) |
Problem: Naively linking roots can create a chain (depth O(n), making find slow).
Solution (Union by Rank): Keep track of the height (rank) of each tree. Always attach the shorter tree under the taller one.
union(x, y):
rx = find(x), ry = find(y)
if rx == ry: return
if rank[rx] < rank[ry]: swap(rx, ry)
parent[ry] = rx
if rank[rx] == rank[ry]: rank[rx] += 1
Idea: During find(x), after finding the root, make every node on the path point directly to the root.
find(x):
if parent[x] != x:
parent[x] = find(parent[x])
return parent[x]
find calls on the same chain are O(1).KruskalMST(G, w):
for each vertex v in V: # makeset × |V|
makeset(v)
sort edges E by weight w # O(E log E)
F = ∅
for each edge (u, v) in E: # O(E α(V))
if find(u) ≠ find(v):
union(u, v)
F = F ∪ {(u, v)}
if |F| == |V| - 1: break
return F
Time complexity:
makeset + 2E find + (V-1) union: O((E+V)\,\alpha(V)) = O(E\,\alpha(V))Kruskal’s algorithm correctly computes an MST.
We prove this by a greedy exchange argument:
Case 1: e \in M. Trivial — set M' = M, invariant preserved.
Case 2: e \notin M. Then M \cup \{e\} contains a cycle C.
Construct M' = M \cup \{e\} - \{e'\}:
The exchange argument is the heart of greedy correctness proofs:
We will see this pattern again in Prim’s algorithm, Huffman codes, and Matroids.
MST definition — minimum-weight spanning tree in a graph
Cut and Cycle properties — fundamental characterizations of MST edges
Kruskal’s algorithm — repeatedly add the cheapest non-cycle-creating edge
Union-Find — efficient cycle detection via DSU with path compression and union by rank
Correctness proof — greedy exchange argument
| Technique | Time complexity |
|---|---|
| Kruskal’s + Union-Find | O(E \log V) |
| Kruskal’s + Union-Find (edges pre-sorted) | O(E\,\alpha(V)) |
CS F364: Design & Analysis of AlgorithmsTulasimohan Molli