Proofs: Generic minimum spanning tree method
These are the human proofs of Generic minimum spanning tree method, at full length.
The generic MST method returns a minimum spanning forest for every choice of cuts full
This proof shows: correctness, termination.
Claim. Let be a finite undirected graph with vertices, components and a real weight on each edge; ties, parallel edges and self-loops are allowed. For each sequence of choices made at line L3, GENERIC-MST stops after exactly iterations, and the set that it returns is a minimum spanning forest of .
Setup. A spanning forest is an acyclic edge set with the components of ; each has edges. A cut respects when no edge of has exactly one end in .
Lemma 1. If is a forest, a cut respects if and only if is a union of vertex sets of trees of . Each edge that crosses such a cut joins two different trees of .
Proof. If is a union of trees, each edge of lies in one tree and has both ends in or both outside. Conversely, if cuts a tree, the tree has a vertex in and one outside, and the path between them in the tree has an edge with exactly one end in . For the second part, an edge with one end in and one outside cannot have both ends in one tree, because each tree is inside or outside it.
Lemma 2 (the cut property, forest form). If is a subset of some minimum spanning forest , the cut respects , and is a light edge of the cut, then is a subset of some minimum spanning forest.
Proof. If we are done. Else let , , . The vertices and are in one component of , so has a path from to , and has an edge that crosses the cut; because respects the cut. The set is a spanning forest: removing splits one tree into a part with and a part with , and joins them again. Since is light, and , so is minimum, and it contains .
Invariant. At the test of line L2, is a subset of some minimum spanning forest, and in particular is a forest.
- Initialization. is a subset of every minimum spanning forest, and one exists because is finite and contains a spanning forest.
- Maintenance. The cut of line L3 respects , and the edge of line L4 is light for it. Lemma 2 shows that is a subset of some minimum spanning forest, so the invariant holds after line L5. The edge of line L4 exists, since line L3 chooses a cut that some edge crosses. Such a cut exists whenever the test of line L2 is true: the tree at one end of an edge that joins two trees is a valid .
Termination. By Lemma 1, the edge added at line L5 joins two different trees of , so stays a forest and its number of trees drops by exactly one in each iteration. The number of trees starts at and is never less than , because the trees of lie inside the components of . So there are at most iterations, and the loop stops.
Conclusion. When the test of line L2 is false, no edge of joins two different trees of . So each component of lies inside one tree of , and each tree of lies inside one component of . Thus is a spanning forest, with edges, and the loop ran exactly times. By the invariant, for a minimum spanning forest , which also has edges, so .