Proofs: Chazelle's minimum spanning tree algorithm
These are the human proofs of Chazelle's minimum spanning tree algorithm, at full length.
The soft-heap filter returns the minimum spanning forest full
This proof shows: correctness, termination.
This proof is for the simplified algorithm SOFT-HEAP-MSF on the page. Chazelle's full algorithm rests on the same two lemmas, the contractibility of the pieces (Lemma 2) and the filter (Lemma 3), and its time analysis is in the paper.
Let be a finite undirected graph without self-loops (they are dropped at the start), with parallel edges allowed. Each edge has the key , where is its index. Keys are compared lexicographically, so distinct edges have distinct keys. All current keys of the soft heaps are keys of edges, so they live in the same totally ordered set. For a set of edges , is the unique minimum spanning forest of the graph under the key order. "Minimum" means least in the order on the sorted list of keys, which for distinct keys is the same as least total key.
Facts
Fact 1 (cut property). Let be a set of edges contained in some minimum spanning forest for a weight function (ties allowed). Let be a set such that no edge of has exactly one end in , and let be an edge with exactly one end in such that for each such edge . Then is contained in some minimum spanning forest for . This is the cut property in its form with ties.
Fact 2 (cycle property, distinct keys). An edge is not in if and only if has a cycle through on which has the largest key. See the cycle property.
Fact 3 (exchange). Let be a minimum spanning forest for , let , and let be the vertex set of one of the two trees of inside the component of . If an edge has exactly one end in , then .
Proof. The ends of lie in one component of , because is an edge. That component is the component of , since one end of is in . So is a spanning forest with the same components. If , its weight is smaller, a contradiction.
Fact 4. If , then .
Proof. Every edge has, by Fact 2, a cycle in on which it is the heaviest edge. Its fundamental cycle with respect to is such a cycle, and it lies in . So , and . Since , both graphs have the same components, so the two forests have the same number of edges and are equal.
Lemma 1: the soft heap
Lemma 1. In the soft heap of the implementation, every item has a current key at least its own key, the current key of an item never decreases, and DELETE-MIN returns an item whose current key is the smallest current key among all items in the heap.
Proof. The current key of an item is the ckey of the node whose list holds it. We show three invariants: (i) every item's key is at most the ckey of its node; (ii) the ckey of a child is at least the ckey of its parent; (iii) a node with an empty list is a leaf, except during a sift.
All three hold for a new node of rank 0. In SIFT, the child with the smaller ckey is chosen. Its list moves to , and becomes . By (ii), this is at least the old ckey of , so the current keys of the items already in do not decrease. The moved items keep their current key. (i) holds for all of them. The new ckey of is at most the ckey of the other child, by the choice of , and at most the ckeys of the children of , by (ii). Then is sifted recursively, which only raises its ckey, so (ii) is kept. If ends with an empty list, the loop in SIFT has stopped, so is a leaf, and it is removed. This keeps (iii).
A new node of a link is sifted at once, and its ckey becomes the ckey of a child. In DELETE-MIN, a root with an empty list is either sifted or, if it is a leaf, removed.
Items move only up the tree, and only by SIFT. So, by the argument above, current keys never decrease. DELETE-MIN takes an item from a root of smallest ckey. By (ii), every node has a ckey at least that of its root, so every item in the heap has a current key at least the returned one.
Lemma 2: the pieces are contractible for the corrupted keys
Number the soft heaps in the order in which they are made at line L3. Each edge enters a given heap at most once. The root inserts each of its edges once, and line L7 skips edges whose other end is already in the piece. For an edge and a heap that held it, let be the current key of when it was deleted from (line L5), or when was discarded (line L8). Define
By Lemma 1, . Lines L5 and L8 put into whenever some . So
Call an edge a tree edge if it is added at line L7 (the edge that brings into ) or used to join two pieces at line L6. Let be the set of tree edges.
Lemma 2. Some minimum spanning forest for (ties allowed) contains . Every final piece, after all joins, is spanned by the tree edges inside it.
Proof. We add the tree edges to in the order of the run and apply Fact 1 with at each step. Note that is fixed by the whole run, so the comparisons below are between final values.
Consider the moment when a tree edge is found by DELETE-MIN from the heap of the piece being grown. Here is its vertex set at that moment, and .
- The cut respects . The tree edges added so far lie inside or inside earlier pieces, and earlier pieces are disjoint from . A join only happens at the end of the growth of a piece.
- Every edge with exactly one end in is in at this moment. Let with and . When entered (or when ), was not in , so was inserted into . If had been deleted from before, then at that time its far end was in (it was skipped), or it brought its far end into , or it ended the growth of . The first two cases contradict , and the third contradicts the fact that is still growing.
- So is light for . For each such , Lemma 1 gives the current key of now the current key of now . It remains to show .
- If is added at line L7, both of its ends are now in . An earlier heap holds an edge only if one of its ends is in an earlier piece, and a later heap only if one of its ends is free when it is inserted. So is the only heap that holds , and .
- If joins to an earlier piece at line L6, then , so by (1) and Lemma 1, .
By Fact 1, stays inside a minimum spanning forest for after each addition. Since is finite, the final is contained in one such forest .
A grown piece is spanned by its line-L7 edges, because each one brings a new vertex in and attaches it to the piece. A join adds an edge between two spanned pieces. So every final piece is spanned by the tree edges inside it.
Lemma 3: the filter
Let be the final pieces. Let be the multigraph whose vertices are the pieces. For each edge whose ends lie in different pieces, has an edge between those pieces, with the same key. This is the graph of line L10.
Lemma 3. , where the edges of are identified with the edges of they come from.
Proof. Let with .
Case 1: both ends of are in one piece . If , then by Fact 2 some cycle of has as its heaviest edge. That is also a cycle of , so by Fact 2, a contradiction.
Case 2: the ends of are in different pieces. Then is an edge of . Suppose . By Fact 2, has a cycle through on which is the heaviest edge. As a cycle, visits each piece at most once. At a piece that it visits, it arrives at a vertex and leaves from a vertex , along two edges of . By Lemma 2, contains a spanning tree of . Let be the path from to in that tree, which is empty if . Then .
Let be the closed walk in that follows the edges of and crosses each visited piece along .
Claim. Every edge on a path has .
Remove from , and let be the side that contains . Since lies on the path in , . A closed walk crosses the cut an even number of times, counted with multiplicity. Consider the edges of :
- itself is used once, since the paths lie in different pieces and a path uses each edge once;
- no other edge of crosses the cut, because is a side of ;
- the edges of are the only other edges of .
So some edge of crosses the cut. Since , it is an edge of , so , and by (1). By Fact 3, applied to and , . Since is the heaviest edge of , . Together:
Moreover , since has both ends in and does not. Distinct edges have distinct keys, so . This proves the claim.
Every edge of other than is lighter than : the edges of by the choice of , and the edges of the paths by the claim. The edge occurs exactly once in , because it is not inside a piece. Removing it from leaves a walk between the two ends of that does not use , and that walk contains a path. With , the path forms a cycle of on which is the heaviest edge. By Fact 2, , a contradiction.
The theorem
Theorem. SOFT-HEAP-MSF terminates and returns .
Proof. By induction on .
Base. If base, line L1 returns Kruskal's result, which is .
Step. Assume base and . Lines L2 to L8 terminate, because each iteration deletes an item from a finite heap. Let be the first vertex, in the order of line L3, that has an edge. When is reached, it is still free, because a piece made earlier was grown from a vertex without edges and so stayed alone. So starts a piece, and its heap is not empty. Since , line L5 deletes some edge with . Then one of three things happens:
- ;
- joins the piece at line L7, so is inside a final piece;
- is in an earlier piece and the pieces are joined, so is again inside a final piece.
In each case is not an edge of . So has at most edges, and by the induction hypothesis, line L10 terminates and returns .
Lines L9 and L12 are Kruskal's algorithm, which returns of its input under the key order. By Lemma 3, , and . By Fact 4, line L12 returns .
The keys order the edges first by weight. So is a minimum spanning forest for the weights , and when weights tie it is the one that Kruskal's algorithm picks with ties broken by index. If is disconnected, it is a minimum spanning forest, one tree per component.