Algorithm Search⌘K

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 G=(V,E)G = (V, E) be a finite undirected graph with nn vertices and a real weight on each edge. Parallel edges are allowed, weights may tie, and GG need not be connected; self-loops are dropped at the start, since no forest contains one. Give each edge the key (w(e),i)(w(e), i), where ii is its index in the input, and compare keys lexicographically. Keys are distinct, so for every subgraph HH of GG (or of a graph obtained from GG by contraction) there is exactly one minimum spanning forest for the keys, written MSF(H)\mathrm{MSF}(H); 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 MSF(G)\mathrm{MSF}(G). The coins change only the running time.

Facts used

Fact 1 (cut property). For every vertex vv with an edge, the edge of least key at vv is in MSF(H)\mathrm{MSF}(H). It is the edge of least key that crosses the cut ({v},V∖{v})(\{v\}, V \setminus \{v\}); see the cut property.

Fact 2 (cycle property). If an edge ee lies on a cycle of HH and has the largest key on that cycle, then e∉MSF(H)e \notin \mathrm{MSF}(H); see the cycle property. Consequently, deleting such an edge does not change MSF(H)\mathrm{MSF}(H): the forest does not use ee, and it stays a minimum spanning forest of the smaller graph, which has the same components.

Fact 3 (contraction). Let C⊆MSF(H)C \subseteq \mathrm{MSF}(H), and let H/CH / C be HH with each tree of CC contracted to one vertex and the loops removed; each remaining edge keeps its key and its identity. Then MSF(H)=C∪MSF(H/C)\mathrm{MSF}(H) = C \cup \mathrm{MSF}(H / C).

Proof of Fact 3. Spanning forests of HH that contain CC correspond one to one to spanning forests of H/CH / C, by deleting or adding the edges of CC: a set F′⊆E(H/C)F' \subseteq E(H / C) is acyclic and has the components of H/CH / C exactly when C∪F′C \cup F' is acyclic and has the components of HH. The key sums differ by the constant total of CC. The unique minimum spanning forest of HH contains CC, so it is the image of the minimum of H/CH / C. □\square

The Borůvka steps

Lemma 1. One call of the Borůvka step on a graph HH returns a set P⊆MSF(H)P \subseteq \mathrm{MSF}(H) and the graph H/PH / P, with isolated vertices removed, in which the number of vertices is at most half the number of vertices of HH that have an edge.

Proof. Each selected edge is the edge of least key at some vertex, so P⊆MSF(H)P \subseteq \mathrm{MSF}(H) by Fact 1; in particular PP 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 PP 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. □\square

By Fact 3, after line L2, MSF(G)=C∪MSF(G′)\mathrm{MSF}(G) = C \cup \mathrm{MSF}(G'), where CC is the set of edges chosen in the two steps and G′G' is the contracted graph.

The filtering step

Let HH be the sample of line L3 and F=MSF(H)F = \mathrm{MSF}(H), which the recursive call of line L4 returns by induction. For an edge e=(u,v)e = (u, v) of G′G', call ee FF-heavy if uu and vv lie in the same tree of FF and the key of ee is larger than every key on the path PF(u,v)P_F(u, v) in FF; otherwise ee is FF-light. Line L5 keeps exactly the FF-light edges; call this graph G′′G''.

Lemma 2. MSF(G′′)=MSF(G′)\mathrm{MSF}(G'') = \mathrm{MSF}(G').

Proof. FF is a set of edges of G′G', since H⊆G′H \subseteq G'. An FF-heavy edge ee closes, with the path PF(u,v)P_F(u, v), a cycle of G′G' on which it has the largest key, so by Fact 2 it is not in MSF(G′)\mathrm{MSF}(G'). Deleting all FF-heavy edges one at a time, each still closes the same cycle with FF, since no edge of FF is ever deleted (an edge of FF has a key equal to the maximum of its own one-edge path, so it is FF-light). By Fact 2, applied at each deletion, the minimum spanning forest does not change. □\square

The theorem

Theorem. On every sequence of coin flips, KKT stops and returns MSF(G)\mathrm{MSF}(G).

Proof. By induction on the number NN of vertices that have an edge.

Termination. If the graph has no edge, line L1 returns. Otherwise the first Borůvka step makes NN at least halve (Lemma 1), so G′G' has N′≤N/2<NN' \le N/2 < N vertices with edges, and so do the sample HH and the filtered graph G′′G'', which are subgraphs of G′G' on its vertex set. So both recursive calls are on graphs with fewer than NN vertices with edges, and the recursion ends.

Correctness. If line L1 or the early return inside line L2 ends the call, the answer is ∅\emptyset, or CC with no edge left, which is MSF(G)\mathrm{MSF}(G) by Fact 3. Otherwise, by the induction hypothesis, line L4 returns F=MSF(H)F = \mathrm{MSF}(H) and line L6 returns MSF(G′′)\mathrm{MSF}(G''). By Lemma 2 this is MSF(G′)\mathrm{MSF}(G'), and line L6 returns C∪MSF(G′)=MSF(G)C \cup \mathrm{MSF}(G') = \mathrm{MSF}(G) by Fact 3. Nothing depended on which edges were sampled. ■\blacksquare

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.

Back to Karger-Klein-Tarjan algorithm