Proofs: Yao's minimum spanning tree algorithm
These are the human proofs of Yao's minimum spanning tree algorithm, at full length.
Yao's algorithm returns the minimum spanning forest in O(m log log n) time full
This proof shows: correctness, termination, complexity.
Claim. Let be a finite undirected multigraph with vertices, edges and real weights; self-loops, parallel edges, ties and several components are allowed. Order the edges by the key . Then YAO-MST stops and returns the unique minimum spanning forest for this order, which is a minimum spanning forest for . It runs in time.
Facts used
Uniqueness. All keys are distinct, so the minimum spanning forest for the keys is unique; call it . A forest of least total key order is also of least total weight for , because the weight order is a coarsening of the key order: Kruskal's algorithm with the key order is a valid run of Kruskal's algorithm for .
Cut property. If is the vertex set of a component of a forest , and is the edge of least key with exactly one end in , then . Proof. If , the path in between the ends of crosses from to by some edge , and has a larger key than . Then is a spanning forest with the same components and a smaller key sum, which is impossible.
Invariant
Invariant I. At the start of each phase of line L2 and of each pass of line L7, , and the components of the disjoint-set structure are the components of .
It holds at line L1, where . In one phase, every chosen edge is the least key edge that leaves the component ; this is immediate in line L2, and in line L13 it is Lemma 1 below. By the cut property, every chosen edge is in . So together with all chosen edges is a subset of the forest , and adding them one by one never closes a cycle; line L13 skips an edge only when its ends are already merged, which happens only when two components chose the same edge. Merging along the added edges keeps the second part of the invariant.
Lemma 1: line L11 finds the least leaving edge at v
Lemma 1. At line L11, if has an edge to another component, then exists and is the least key edge at that leaves the component of . Otherwise does not exist.
Proof. Two facts hold for all at all times.
(a) Every edge that was removed from a group of had both ends in one component when it was removed, and components only merge, so it still has both ends in one component.
(b) The groups hold no edge that leaves a component. Indeed, grows only in line L10, after became empty by removals, so every edge that was ever in these groups was removed, and by (a) it does not leave a component.
After line L10, either is nonempty and holds only edges that leave the component of (the inner ones were just removed), or and the group is empty. In the first case, let be the least key edge at that leaves the component. By (b), is not in a group before . Every key in is below every key in later groups, by line L5, and contains a leaving edge, so is not in a later group either. So , and it is the least edge there. In the second case, all groups are empty or hold no leaving edge, by (b) and the emptiness of the last group, so has no leaving edge.
So in line L12, the least of over the vertices of inside , is the least key edge that leaves : every edge of that leaves is an edge of at some vertex of inside , since keeps all edges between different components after line L2.
Termination and the result
Each pass of lines L7 to L13 in which some component has a leaving edge adds at least one edge to , and has at most edges, so the loop stops. When it stops, no edge leaves any component. Then the components of are the components of , so is a spanning forest with edges, where is the number of components of . Also and , so .
Running time
Let . Each plain Borůvka phase costs . In each phase, each component that has a leaving edge merges with at least one other, so after phases each component with a leaving edge has at least vertices, and has vertices with edges. The cost of line L2 is .
Line L5 on a list of edges uses levels of splitting, and each level selects one rank in each part and splits it, which costs by linear-time selection. So lines L4 to L6 cost , as . Each group has at most edges.
In lines L7 to L13, each pass at least halves the number of components that have a leaving edge, so there are at most passes. In one pass, vertex reads its current group and every group it empties. Each edge is removed from each of its two lists at most once, so removals cost over the whole run. Reading the final current group costs , so a pass costs apart from removals. Over all passes this is , since and .
The total is .