Algorithm Search⌘K

Proofs: Borůvka's algorithm

These are the human proofs of Borůvka's algorithm, at full length.

Borůvka's algorithm returns a minimum spanning forest in at most floor(lg n) + 1 rounds full

This proof shows: correctness, termination.

Claim. Let G=(V,E)G = (V, E) be a finite undirected graph with n≥1n \ge 1 vertices and a real weight w(e)w(e) on each edge, with ties, parallel edges and self-loops allowed, and GG not necessarily connected. Let ≺\prec be the strict total order on EE given by (w(e),id(e))(w(e), \mathrm{id}(e)) in lexicographic order, with distinct ids. Then BORŮVKA(G,w)(G, w) stops after at most ⌊lg⁡n⌋+1\lfloor \lg n \rfloor + 1 rounds and returns a minimum spanning forest of GG.

Setup. Let cc be the number of components of GG. Each spanning forest of GG has n−cn - c edges. For S⊆VS \subseteq V, an edge crosses SS when it has exactly one end in SS. Let T∗T^* be the output of Kruskal's algorithm when line L3 of that algorithm sorts the edges by ≺\prec. Since ≺\prec lists the edges in non-decreasing order of weight, T∗T^* is a minimum spanning forest of GG, by the correctness of Kruskal's algorithm.

Lemma 1. If S⊆VS \subseteq V and ee is the ≺\prec-least edge that crosses SS, then e∈T∗e \in T^*.

Proof. Let e=(u,v)e = (u, v) with u∈Su \in S, v∉Sv \notin S. When Kruskal's algorithm reaches ee, it has seen only edges f≺ef \prec e, and none of them crosses SS. So each tree of its current forest has all its vertices in SS or all outside SS, and uu and vv are in different trees. Kruskal's algorithm therefore adds ee. □\square

Lemma 2 (invariant). At the start of each round, F⊆T∗F \subseteq T^*. In particular FF is a forest.

Proof. By induction on the rounds. Before the first round F=∅F = \emptyset. Assume F⊆T∗F \subseteq T^* at the start of a round. Line L3 labels the trees of (V,F)(V, F). For a tree CC, after the loop of lines L5 to L8, best[C]\mathrm{best}[C] is nil if no edge crosses the vertex set of CC, and otherwise it is the ≺\prec-least edge that crosses it, because the loop looks at every edge that crosses CC (each such edge has comp[u]≠comp[v]\mathrm{comp}[u] \ne \mathrm{comp}[v] with CC one of the two) and keeps the least one. By Lemma 1, each edge of AA is in T∗T^*. So F∪A⊆T∗F \cup A \subseteq T^* after line L10. A subset of a forest is a forest. □\square

Lemma 3 (rounds). Call a tree of FF open if some edge of GG crosses its vertex set. If a round starts with kk open trees, the next round starts with at most ⌊k/2⌋\lfloor k/2 \rfloor open trees.

Proof. A tree that is not open is a whole component of GG. It picks nothing, no edge reaches it, and it stays as it is and not open. Each open tree CC picks the edge best[C]\mathrm{best}[C], which joins CC to a different tree C′C', and C′C' is open too, since that edge crosses it. So after line L10, each new tree that contains an open tree contains at least two old open trees. A new tree that is open contains at least one old open tree, because a new tree made only of closed trees is a single closed tree. So each new open tree contains at least two old open trees, the new open trees are disjoint, and there are at most ⌊k/2⌋\lfloor k/2 \rfloor of them. □\square

Termination and the count. At the start of round 1 there are k1≤nk_1 \le n open trees. By Lemma 3, round rr starts with kr≤n/2r−1k_r \le n / 2^{r-1} open trees. A round adds an edge if and only if kr≥1k_r \ge 1, and if kr≥1k_r \ge 1 then kr≥2k_r \ge 2, because an open tree has an edge to another tree of its component, and that tree is open too. So a round that adds edges needs n/2r−1≥2n / 2^{r-1} \ge 2, that is r≤lg⁡nr \le \lg n, so at most ⌊lg⁡n⌋\lfloor \lg n \rfloor rounds add edges. The round after the last of them has A=∅A = \emptyset and stops the loop at line L11. In total there are at most ⌊lg⁡n⌋+1\lfloor \lg n \rfloor + 1 rounds. Each round does a finite amount of work, so the algorithm stops.

Conclusion. In the last round A=∅A = \emptyset, so no edge crosses the vertex set of any tree of FF. Then each edge of GG has both ends in one tree of FF, so each component of GG lies inside one tree of FF. Since F⊆EF \subseteq E, each tree of FF lies inside one component of GG. So FF has the components of GG and, by Lemma 2, is a forest: it is a spanning forest with n−cn - c edges. Lemma 2 also gives F⊆T∗F \subseteq T^*, and T∗T^* has n−cn - c edges, so F=T∗F = T^*, a minimum spanning forest. ■\blacksquare

Why the strict order is needed. In a triangle a,b,ca, b, c with three edges of weight 1, the order by weight alone allows best[a]=ab\mathrm{best}[a] = ab, best[b]=bc\mathrm{best}[b] = bc and best[c]=ca\mathrm{best}[c] = ca. Then AA is the whole triangle, which is a cycle. Lemma 1 fails for such picks, because each of the three edges is a lightest edge of its cut but they are not all in one spanning tree.

Back to Borůvka's algorithm