Minimum Spanning Trees
Given a weighted network, how do we connect everything as cheaply as possible? The answer is a minimum spanning tree, and one lemma — the cut property — justifies every correct MST algorithm.
╌╌╌╌
Suppose you must lay cable to connect a set of towns, and every possible connection has a known cost. You want all the towns linked — any town reachable from any other — while spending as little as possible. Laying a redundant link would only waste money, so the cheapest solution can contain no cycle: it is a tree that spans every town. Finding the cheapest such tree is the minimum spanning tree problem, and it is the first place in this course where a greedy strategy is provably optimal.
The problem
Stated precisely, in the shape the rest of this lesson will use:
Here a tree means a connected, acyclic graph, not to be confused with a rooted or rooted-and-ordered tree; an MST has no distinguished root. A spanning tree on vertices always has exactly edges: enough to connect everything, one fewer than would create a cycle.
The word tree
here admits several equivalent characterizations, any one of
which could serve as the definition.
Below, a weighted graph and one of its minimum spanning trees (the thick colored edges). This nine-town graph is the running example for the whole lesson: every trace and every snapshot below runs on it.
The thick tree spans all nine towns with total weight ; no spanning tree is cheaper.
Safe edges and the generic method
Every algorithm in this lesson is an instance of one greedy template: maintain a set of edges that is always a subset of some MST, and at each step add one more safe edge, meaning an edge that can be added to while keeping (some MST).1
- 1
- 2while is not a spanning tree do
- 3find an edge that is safe forthe only hard step
- 4
- 5return
The invariant holds trivially at initialization ( is a subset of any MST), it is maintained by the definition of safe, and at termination it does all the work: has edges and is contained in some MST , but also has exactly edges, so . The loop runs exactly times, once per added edge.
Two things are not obvious. First, a safe edge always exists while is not yet spanning: the invariant gives an MST , and any edge of is safe by definition. Second, and harder, a safe edge must be recognizable without already knowing an MST — otherwise the template is circular. The entire theory of MSTs reduces to two local certificates: the cut property, which certifies that an edge is safe to include, and the cycle property, which certifies that an edge is safe to exclude.
The cut property
First, the vocabulary. A cut is a partition of the vertices into two groups. An edge crosses the cut if its endpoints lie on opposite sides. A cut respects an edge set if no edge of crosses it. An edge crossing the cut is light (or cheapest) if it has the minimum weight of all crossing edges.
Here is the same picture on the nine-town graph. Take , the towns above the dashed line. Five edges cross this cut: – at , – at , – at , – at , and – at . The light one is –, so the cut property guarantees that – belongs to some MST — and indeed it is in the thick tree above. Both Kruskal and Prim will commit to – early, each by building a cut like this one.
Every correct MST algorithm — Borůvka's, Prim's, or Kruskal's — is a strategy for choosing which cut to apply the property to, and all three only ever add edges that obey the cut rule.
The cycle property
The cut property justifies including edges; its mirror image justifies discarding them.2
The fine print matters: the theorem speaks only about edges that lie on a
cycle. An edge on no cycle is a bridge, and a bridge is in every spanning
tree no matter how expensive it is. Heaviest edge of the graph
is not the
same as heaviest edge on a cycle
:
Together the two properties settle the uniqueness question.
Distinctness is sufficient but not necessary. The nine-town graph has ties (two edges of weight , three of weight ) yet a unique MST: every one of the five non-tree edges is the strict maximum on the cycle it closes (– at closes a cycle whose other edges weigh and ; – at beats a path of maximum weight ; and so on), so by the cycle property none of them is in any MST, which forces the remaining eight edges.
Borůvka's algorithm
The oldest MST algorithm (Otakar Borůvka, 1926) is also the most directly cut-rule driven, and it parallelises well.2 The idea: every component, in every round, simultaneously selects its own cheapest outgoing edge.
Maintain a forest , initially the isolated vertices. In each round, each current component looks at the cut , which respects , and selects its lightest crossing edge. By the cut property every such edge is safe, so we add them all at once and merge the components they join. Every component merges with at least one neighbor, so the number of components at least halves each round, and only rounds are needed.
- 1singleton components
- 2while has more than one component do
- 3foreach component of do
- 4the lightest edge crossingsafe by cut rule
- 5foreach distinct edge chosen do
- 6add all exit edges at once
- 7return
Running time. Each round scans all edges to find component-minimum exits in time and there are rounds, so runs in , the same headline bound as Prim and Kruskal, but with the useful property that the per-round work is fully parallel.
One round on six isolated vertices shows the parallel grab. Each singleton (a component of one) points an arrow along its own cheapest incident edge. Vertices and pick each other (both cheapest at ), as do and (at ) and and (at ), so the six arrows name only three distinct edges, and one sweep merges six components into three:
How fast can an MST be found?
The three classical algorithms all land at . Is the log necessary? The answer, developed over decades, is essentially no — and Borůvka's rounds appear in every improvement.
Borůvka as an accelerator. A single Borůvka phase costs and at least halves the vertex count, contracting each component to a single super-vertex. Running phases before switching to Prim yields ; interleaving Borůvka contraction with a Fibonacci-heap priority queue gives Fredman and Tarjan's (1987), where — the iterated logarithm — is at most for any input that fits in the universe.3 The pattern is always the same: use Borůvka to shrink the graph cheaply, then spend the expensive per-edge work on a much smaller instance.
The randomized linear-time algorithm. Karger, Klein, and Tarjan (1995) gave an MST algorithm running in expected time.4 It alternates Borůvka contraction with a sampling step: pick each edge independently with probability , recursively find the MST of the sample, then use that sample-forest to discard every edge that is F-heavy (heavier than the heaviest edge on the sample-tree path between its endpoints — a cycle-property rejection in bulk). A linear-time MST verification procedure certifies the discards, and a sampling lemma bounds the surviving edges by , collapsing the recursion to linear expected work. It is the first MST algorithm to escape the sorting bottleneck entirely.
The deterministic frontier. Whether a deterministic linear-time MST algorithm exists is still open. Chazelle (2000) came closest with using a data structure called the soft heap, which deliberately corrupts a few keys to run faster; and Pettie and Ramachandran (2002) gave a provably optimal deterministic algorithm whose exact running time equals the (unknown) decision-tree complexity of the problem — optimal without anyone knowing what that optimum is.5
The practical takeaway matches the theory: real fast-MST codes run a couple of Borůvka rounds to shrink the graph, then finish with Prim or Kruskal. This continues in Kruskal and Prim, the two algorithms you will actually implement — one growing a forest with union-find, the other a single tree with a priority queue.
Footnotes
- CLRS, Ch. 23 — Minimum Spanning Trees — the generic method, safe edges, and the cut property identifying a safe edge for the greedy MST template. ↩
- Erickson, Ch. 8 — Minimum Spanning Trees — the cut and cycle properties, and Borůvka's component-merging rounds in phases. ↩ ↩2
- Fredman, M. L. & Tarjan, R. E. (1987),
Fibonacci heaps and their uses in improved network optimization algorithms,
Journal of the ACM 34(3), 596–615 — the MST bound. ↩ - Karger, D. R., Klein, P. N. & Tarjan, R. E. (1995),
A randomized linear-time algorithm to find minimum spanning trees,
Journal of the ACM 42(2), 321–328 — expected linear-time MST via sampling and Borůvka contraction. ↩ - Pettie, S. & Ramachandran, V. (2002),
An optimal minimum spanning tree algorithm,
Journal of the ACM 49(1), 16–34 — a provably optimal deterministic MST algorithm; and Chazelle, B. (2000),A minimum spanning tree algorithm with inverse-Ackermann type complexity,
JACM 47(6), 1028–1047. ↩
╌╌ END ╌╌