Proofs: Karger-Klein-Tarjan algorithm
These are the human proofs of Karger-Klein-Tarjan algorithm, at full length.
The Karger-Klein-Tarjan algorithm returns the minimum spanning forest on every run, and stops full
This proof shows: correctness, termination.
Let be a finite undirected graph with vertices and a real weight on each edge. Parallel edges are allowed, weights may tie, and need not be connected; self-loops are dropped at the start, since no forest contains one. Give each edge the key , where is its index in the input, and compare keys lexicographically. Keys are distinct, so for every subgraph of (or of a graph obtained from by contraction) there is exactly one minimum spanning forest for the keys, written ; it is also a minimum spanning forest for the weights.
We prove that KKT (lines L1 to L6 of the page) stops on every sequence of coin flips and returns . The coins change only the running time.
Facts used
Fact 1 (cut property). For every vertex with an edge, the edge of least key at is in . It is the edge of least key that crosses the cut ; see the cut property.
Fact 2 (cycle property). If an edge lies on a cycle of and has the largest key on that cycle, then ; see the cycle property. Consequently, deleting such an edge does not change : the forest does not use , and it stays a minimum spanning forest of the smaller graph, which has the same components.
Fact 3 (contraction). Let , and let be with each tree of contracted to one vertex and the loops removed; each remaining edge keeps its key and its identity. Then .
Proof of Fact 3. Spanning forests of that contain correspond one to one to spanning forests of , by deleting or adding the edges of : a set is acyclic and has the components of exactly when is acyclic and has the components of . The key sums differ by the constant total of . The unique minimum spanning forest of contains , so it is the image of the minimum of .
The Borůvka steps
Lemma 1. One call of the Borůvka step on a graph returns a set and the graph , with isolated vertices removed, in which the number of vertices is at most half the number of vertices of that have an edge.
Proof. Each selected edge is the edge of least key at some vertex, so by Fact 1; in particular has no cycle, and the union-find test that skips edges whose ends are already joined skips only repeats of the same edge, chosen from both ends. Every vertex with an edge is incident to a selected edge, so each tree of that holds such a vertex has at least two vertices, and the contracted graph has at most half as many vertices with edges. Removing isolated vertices does not change any minimum spanning forest.
By Fact 3, after line L2, , where is the set of edges chosen in the two steps and is the contracted graph.
The filtering step
Let be the sample of line L3 and , which the recursive call of line L4 returns by induction. For an edge of , call -heavy if and lie in the same tree of and the key of is larger than every key on the path in ; otherwise is -light. Line L5 keeps exactly the -light edges; call this graph .
Lemma 2. .
Proof. is a set of edges of , since . An -heavy edge closes, with the path , a cycle of on which it has the largest key, so by Fact 2 it is not in . Deleting all -heavy edges one at a time, each still closes the same cycle with , since no edge of is ever deleted (an edge of has a key equal to the maximum of its own one-edge path, so it is -light). By Fact 2, applied at each deletion, the minimum spanning forest does not change.
The theorem
Theorem. On every sequence of coin flips, KKT stops and returns .
Proof. By induction on the number of vertices that have an edge.
Termination. If the graph has no edge, line L1 returns. Otherwise the first Borůvka step makes at least halve (Lemma 1), so has vertices with edges, and so do the sample and the filtered graph , which are subgraphs of on its vertex set. So both recursive calls are on graphs with fewer than vertices with edges, and the recursion ends.
Correctness. If line L1 or the early return inside line L2 ends the call, the answer is , or with no edge left, which is by Fact 3. Otherwise, by the induction hypothesis, line L4 returns and line L6 returns . By Lemma 2 this is , and line L6 returns by Fact 3. Nothing depended on which edges were sampled.
Ties. The order by (weight, index) makes keys distinct, so the answer is the same on every run. For the weights alone it is one of the minimum spanning forests, and an edge of the same weight as a path maximum is kept, which is safe: Lemma 2 deletes only edges strictly heavier in the key order.