Karger–Klein–Tarjan Randomized Minimum Spanning Tree Algorithm
The Karger–Klein–Tarjan algorithm is a randomized comparison-based graph algorithm published by David R. Karger, Philip N. Klein, and Robert E. Tarjan in 1995 that computes the minimum spanning forest of an undirected edge-weighted graph with n vertices and m edges in O(m + n) expected time.
Karger–Klein–Tarjan randomized minimum spanning tree algorithm (commonly abbreviated as the KKT algorithm) is a Las Vegas randomized comparison-based graph algorithm in computation and algorithms published by David R. Karger, Philip N. Klein, and Robert E. Tarjan in 1995 (Journal of the ACM) that computes the minimum spanning tree (or minimum spanning forest) of an arbitrary undirected edge-weighted graph G = (V, E) with n = |V| vertices and m = |E| edges in O(m + n) expected time and O(m + n) worst-case space. Operating in the pointer-machine comparison model—where edge weights are arbitrary real numbers accessed through pairwise order comparisons (w(e1) < w(e2)) without integer bit manipulation or radix addressing—the KKT algorithm resolved a decades-old open question in algorithmic graph theory by proving that minimum spanning forests can be constructed in linear expected time using only weight comparisons. The algorithm interleaves three structural mechanisms: deterministic vertex-set reduction via two rounds of Borůvka's algorithm, independent Bernoulli random edge sampling at probability p = 1/2 to construct a sparse subgraph H, and deterministic linear-time MST verification (Dixon, Rauch, and Tarjan, 1992; King, 1995) to discard edges heavier than the bottleneck path connecting their endpoints in the minimum spanning forest of H.
Historical Background and Computational Model
The Comparison-Based Minimum Spanning Tree Barrier
Let G = (V, E) be an undirected graph with n vertices, m edges, and an injective weight function w : E → ℝ assigning distinct real weights to all edges (ties among equal weights can be broken deterministically by lexicographic vertex-pair indexing). If G is disconnected, the objective is to compute the minimum spanning forest F*(G), defined as the union of the minimum spanning trees of each connected component of G.
For nearly seventy years following Otakar Borůvka's 1926 algorithm, every comparison-based method for constructing F*(G) incurred superlinear overhead on sparse or moderately dense graphs due to priority-queue maintenance or global edge sorting:
- Borůvka's algorithm (1926): Executes up to ⌈log2 n⌉ parallel minimum-incident-edge contraction phases in O(m log n) deterministic time.
- Kruskal's algorithm (1956): Sorts all m edges in O(m log n) comparisons and scans them with a disjoint-set data structure in O(m α(m, n)) overhead.
- Prim's algorithm (1957) with Fibonacci heaps (Fredman and Tarjan, 1987): Achieves O(m + n log n) time, which is linear only when m = Ω(n log n).
- Packetized Fibonacci-heap contractions (Fredman and Tarjan, 1987; Gabow, Galil, Spencer, and Tarjan, 1986): Reduced deterministic comparison complexity first to O(m β(m, n)) and subsequently to O(m log β(m, n)), where β(m, n) = min{i ≥ 1 : log(i) n ≤ m/n}.
In 1990, Michael L. Fredman and Dan E. Willard bypassed the comparison model by introducing fusion trees and the atomic heap on the transdichotomous Word RAM, achieving O(m + n) deterministic time for integer edge weights via word-level multiplication and bit-packing. However, whether O(m + n) complexity was achievable in the comparison decision-tree model remained open until Karger (1993) observed that random edge sampling combined with cycle-property filtering could thin dense graphs, which Karger, Klein, and Tarjan (1995) refined into a recursive linear-expected-time algorithm.
Cut and Cycle Duality Principles
The correctness and filtering mechanics of the KKT algorithm rest on the dual optimality conditions characterizing F*(G) (Tarjan, 1983):
- The Cut Property (Blue Rule): For any subset of vertices S ⊆ V, the minimum-weight edge with one endpoint in S and the other in V \ S belongs to F*(G). Contracting any forest of minimum-incident edges preserves the identity of all remaining edges of F*(G).
- The Cycle Property (Red Rule): For any cycle C in G, the heaviest edge on C does not belong to F*(G). Equivalently, for any forest F ⊆ E and any edge e = (u, v) ∈ E, let PF(u, v) denote the unique simple path between u and v in F when u and v lie in the same connected component of F. Define the bottleneck weight wF(u, v) as the maximum weight w(e') along PF(u, v), with wF(u, v) = +∞ if u and v lie in different components of F. An edge e = (u, v) is called F-heavy if w(e) > wF(u, v), and F-light if w(e) ≤ wF(u, v). By the Cycle Property, no F-heavy edge can belong to F*(G), because e is the heaviest edge on the fundamental cycle PF(u, v) ∪ {e}. Deleting all F-heavy edges from G therefore leaves a sparser subgraph containing every edge of F*(G).
Three Algorithmic Building Blocks
The KKT algorithm achieves O(m + n) expected time by balancing vertex contraction against edge sparsification so that both Recursive Call 1 (on a random sample) and Recursive Call 2 (on the surviving F-light edges) operate on graphs with geometrically smaller vertex counts and bounded expected edge counts.
1. Borůvka Contraction Steps (Vertex Reduction)
Given an input graph G with n vertices and m edges, a single Borůvka step operates as follows:
- For each non-isolated vertex v ∈ V, scan its adjacency list to identify its minimum-weight incident edge emin(v).
- Add the collection of selected edges B = {emin(v) : v ∈ V} to the output minimum spanning forest. Because weights are distinct, B contains no cycles and forms a forest.
- Contract each connected component of (V, B) into a single supervertex using depth-first search, removing self-loops (u, u) and discarding redundant parallel edges between the same pair of supervertices by keeping only the minimum-weight edge.
Every non-isolated vertex joins a connected component of size at least 2 during one Borůvka step, halving the number of vertices. Executing two consecutive Borůvka steps takes O(m + n) deterministic time and reduces the number of surviving vertices to at most:
While Borůvka steps reduce the vertex count by a factor of 4, they are not guaranteed to reduce the edge count m by a constant factor on dense graphs. To reduce m simultaneously, the KKT algorithm applies random edge sampling.
2. Random Edge Sampling and the Random Sampling Lemma
After two Borůvka steps produce a contracted graph G' = (V', E') with n' ≤ n/4 vertices and m' ≤ m edges, the algorithm constructs a random subgraph H = (V', EH) by independently including each edge e ∈ E' in EH with probability p = 1/2. The expected number of edges in H is E[|EH|] = m' / 2 ≤ m / 2. The algorithm then makes Recursive Call 1 on H to compute its minimum spanning forest F = F*(H).
The Random Sampling Lemma of Karger, Klein, and Tarjan proves that F = F*(H) is so close to F*(G') that the expected number of F-light edges in G' is at most n' / p = 2n' ≤ n / 2—independent of m'!
Proof of the Random Sampling Lemma (Deferred Coin-Flip Argument)
Lemma (Karger, Klein, and Tarjan, 1995): Let G' = (V', E') be any weighted graph on n' vertices, let H be obtained by sampling each edge of E' independently with probability p ∈ (0, 1), and let F = F*(H) be the minimum spanning forest of H. Then the number of F-light edges in E' is stochastically dominated by a negative binomial distribution with parameters n' − 1 and p, and its expectation is at most (n' − 1) / p < n' / p.
Proof: Sort all edges of E' in increasing order of weight: e1, e2, …, em' with w(e1) < w(e2) < ⋯ < w(em'). Recall that Kruskal's algorithm constructs F = F*(H) by scanning the sampled edges in increasing order of weight and adding ei ∈ H to F if and only if its endpoints lie in different connected components of the forest Fi−1 constructed from {e1, …, ei−1} ∩ H.
Using the principle of deferred decisions, scan e1, e2, …, em' one edge at a time and flip the coin for ei = (ui, vi) only when needed:
- Case A (ui and vi are already connected in Fi−1): Every edge on the path between ui and vi in Fi−1 precedes ei in the sorted order and has weight less than w(ei). Thus w(ei) > wF(ui, vi), so ei is F-heavy regardless of its coin toss, and Kruskal's algorithm on H rejects ei even if sampled.
- Case B (ui and vi lie in different components of Fi−1): No path in Fi−1 connects ui and vi, so ei is F-light. Now flip the coin for ei (heads with probability p, tails with probability 1 − p). If the coin lands heads, ei enters H and is added to Fi−1 by Kruskal's algorithm, increasing |F| by 1. If the coin lands tails, ei is not in H (Fi = Fi−1), but still counts as an F-light edge of G'.
Because any forest F on n' vertices contains at most n' − 1 edges, Case B can produce at most n' − 1 heads across the entire scan. Every F-light edge corresponds to a trial in Case B before the (n' − 1)-th head. The expected number of Bernoulli(p) trials required to achieve n' − 1 heads is (n' − 1) / p. For p = 1/2, the expected number of F-light edges in G' is at most 2(n' − 1) < 2n'.
3. Linear-Time MST Verification and Heavy-Edge Filtering
Once Recursive Call 1 returns the minimum spanning forest F of H, the algorithm must identify and delete all F-heavy edges in G', retaining only Elight = {e = (u, v) ∈ E' : w(e) ≤ wF(u, v)}. This is the MST verification problem (tree path-maxima query problem). While Robert E. Tarjan (1979) answered offline path-maxima queries in O(m' α(m', n')) comparisons via path compression, the KKT algorithm achieves linear O(m' + n') deterministic time using the verification algorithm of Brandon Dixon, Monika Rauch, and Robert E. Tarjan (1992), simplified by Valerie King (1995) and Torben Hagerup (2009):
- Conversion to Full Branching Borůvka Tree (King, 1995): Run Borůvka's algorithm on the tree F in O(n') time and record the component-merge hierarchy as a rooted branching tree BF of height at most ⌈log2 n'⌉ with n' leaves. King proved that for any pair of vertices u, v ∈ V', the bottleneck path weight wF(u, v) in F equals the maximum edge weight on the unique path between leaves u and v in BF.
- Lowest Common Ancestor (LCA) and Micro-Tree Decomposition: Using linear-time Gabow–Tarjan LCA preprocessing on BF, split each query (u, v) into two ancestor-descendant path-maxima queries (a, u) and (a, v) where a = LCA(u, v), and evaluate them in O(m' + n') comparisons via Komlós's (1985) downward bit-vector stack algorithm and small micro-tree lookup tables.
After deleting all F-heavy edges in O(m' + n') time, the algorithm makes Recursive Call 2 on Glight = (V', Elight), which has n' ≤ n/4 vertices and expected edge count E[|Elight|] < 2n' ≤ n/2.
Complete Algorithm and Expected-Time Recurrence
Recursive Procedure
Given an undirected weighted graph G = (V, E) with n vertices and m edges:
- Base Case: If E = ∅, return ∅.
- Step 1 (Borůvka Contraction): Execute two Borůvka phases on G, collecting the contracted edges into F0 and producing G' = (V', E') with n' ≤ n/4 vertices and m' ≤ m edges.
- Step 2 (Random Sampling): Form H = (V', EH) by sampling each edge e ∈ E' independently with probability p = 1/2.
- Step 3 (Recursive Call 1): Compute F = KKT(H), the minimum spanning forest of H.
- Step 4 (Verification Filtering): Run linear-time MST verification on (G', F) to extract the F-light edge set Elight = {e = (u, v) ∈ E' : w(e) ≤ wF(u, v)}.
- Step 5 (Recursive Call 2): Compute F' = KKT(V', Elight) and return F0 ∪ F'.
Solution of the Stochastic Recurrence
Let T(m, n) denote the expected number of comparisons and pointer operations on a graph with m edges and n vertices. Combining the deterministic O(m + n) work of Steps 1, 2, and 4 with the two recursive calls gives:
Viewing the recursion as a binary tree where every node at depth d ≥ 0 has at most nd ≤ n / 4d vertices:
- Vertex Work Across Depth d: Across all 2d recursion nodes at depth d, the sum of vertex counts is at most 2d · (n / 4d) = n / 2d, which sums over d ≥ 0 to 2n = O(n).
- Edge Work Along Left and Right Branches: Along the root's left branch (sampling), expected edge counts halve at each step (m → m/2 → m/4), summing to 2m. Whenever a node at depth d branches right (filtering), its child receives at most 2nd+1 ≤ n / (2 · 4d) edges in expectation, and its subsequent left-branch chain sums to at most n / 4d edges. Summing over all 2d nodes at depth d yields ∑d≥0 2d (n / 4d) = 2n.
Thus E[T(m, n)] ≤ 2c(m + n) = O(m + n). Moreover, by negative binomial tail concentration across the recursion tree, the running time is O(m + n) with high probability 1 − e−Ω(m).
Comparison of Linear and Near-Linear MST Algorithms
| Algorithm | Year | Computational Model | Randomization | Time Complexity | Key Algorithmic Technique |
|---|---|---|---|---|---|
| Borůvka's Algorithm | 1926 | Comparison Pointer Machine | Deterministic | O(m log n) worst-case | Parallel component minimum-edge contraction |
| Prim's Algorithm (Fibonacci Heap) | 1987 | Comparison Pointer Machine | Deterministic | O(m + n log n) worst-case | Amortized O(1) decrease-key in Fibonacci heap |
| Gabow–Galil–Spencer–Tarjan | 1986 | Comparison Pointer Machine | Deterministic | O(m log β(m, n)) worst-case | Packetized Fibonacci heap growth phases |
| Fredman–Willard Atomic Heap | 1994 | Transdichotomous Word RAM | Deterministic | O(m + n) worst-case | Fusion tree bit-sketching + Q-heap lookup tables |
| Karger–Klein–Tarjan (KKT) | 1995 | Comparison Pointer Machine | Las Vegas Randomized | O(m + n) expected | Borůvka contraction + p = 1/2 sampling + MST verification |
| Chazelle Soft-Heap MST | 2000 | Comparison Pointer Machine | Deterministic | O(m α(m, n)) worst-case | Soft heap deliberate key corruption along vertex chains |
| Pettie–Ramachandran Optimal MST | 2002 | Comparison Pointer Machine | Deterministic | O(𝒯*(m, n)) worst-case | Soft heap + precomputed optimal decision trees on micro-graphs |
Frequently Asked Questions
Is the Karger–Klein–Tarjan algorithm a Monte Carlo or a Las Vegas randomized algorithm?
The KKT algorithm is a Las Vegas algorithm: it always outputs the true minimum spanning forest and never errs. Randomness is used only in Step 2 to select a sparse subgraph H with probability p = 1/2 so that its spanning forest F filters out F-heavy edges. Because every discarded edge is certified by the deterministic Cycle Property to be heavier than the fundamental cycle it forms with F, no edge of the true minimum spanning forest is ever discarded.
Why are two Borůvka steps required before each random sampling phase?
If only one Borůvka step were executed per phase, the vertex count would drop by a factor of 2 (n' ≤ n/2) while spawning 2 recursive calls, causing the 2d subproblems at depth d to sum to Θ(n) vertices per level across log2 n levels (O(m + n log n) time). Executing two Borůvka steps reduces the vertex count to at most n/4 while making 2 recursive calls, so total vertex work at depth d decays geometrically as 2d · (n / 4d) = n / 2d and sums to O(n).
Why does the Random Sampling Lemma bound the number of F-light edges by 2n regardless of m?
When scanning all edges of G' in increasing weight order, an edge e is F-light if and only if its endpoints lie in different connected components of the sampled forest F constructed so far. Each such edge is included in H (and added to F) with probability p = 1/2. Because F is an acyclic forest on n' vertices, it can accept at most n' − 1 edges before spanning all components. Waiting for at most n' − 1 heads from a fair coin (p = 1/2) takes at most 2(n' − 1) < 2n' trials in expectation, regardless of m'.
References
- 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. https://doi.org/10.1145/201019.201022
- Dixon, B., Rauch, M., & Tarjan, R. E. (1992). Verification and sensitivity analysis of minimum spanning trees in linear time. SIAM Journal on Computing, 21(6), 1184–1192. https://doi.org/10.1137/0221070
- King, V. (1995). A simpler minimum spanning tree verification algorithm. Algorithmica, 18(2), 263–270. https://doi.org/10.1007/BF02523171
- Pettie, S., & Ramachandran, V. (2002). An optimal minimum spanning tree algorithm. Journal of the ACM, 49(1), 16–34. https://doi.org/10.1145/505241.505243
- King, V. (1997). A simpler minimum spanning tree verification algorithm. Algorithmica, 18(2), 263–270. https://doi.org/10.1007/BF02523171