Algorithm Search⌘K

Proofs: Fredman-Tarjan algorithm

These are the human proofs of Fredman-Tarjan algorithm, at full length.

The Fredman-Tarjan algorithm returns a minimum spanning forest and stops after few phases 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 w(e)w(e) on each edge. Parallel edges and self-loops are allowed, weights may tie, and GG need not be connected. Order the edges by the pair (w(e),index of e)(w(e), \text{index of } e). This is a strict total order that refines the order by weight, so a spanning forest that is minimum for this order is a minimum spanning forest (MSF) for ww. With all keys distinct, the MSF for the order is unique; call it F∗F^*.

We prove that the algorithm (lines L1 to L11 of the page) stops, and that the set FF it returns is F∗F^*.

Facts used

Fact 1 (the cut property for distinct keys). If SS is a set of vertices and ee is the edge of least key with exactly one end in SS, then e∈F∗e \in F^*. This is the cut property for a strict order.

Fact 2 (what a contracted vertex is). At the start of each phase, every vertex of the current graph HH stands for a set of vertices of GG, and these sets partition the vertices that still have edges. Every edge of HH stands for one edge of GG whose ends lie in two different sets, and it is the edge of least key among all edges of GG between those two sets. Every edge of GG with both ends in one set is a loop of HH and has been removed.

Proof of Fact 2. By induction on the phases. At the start, the sets are single vertices, and line L10 (the same cleaning step, applied to the input) removes loops and keeps the least key among parallel edges. At the end of a phase, line L10 replaces each vertex of HH by the tree of this phase that holds it and merges their sets. An edge of GG between two new sets was, by induction, represented by an edge of HH between two old sets in different trees, or was dominated by such an edge with a smaller key; so keeping the least key over the parallel edges of HH keeps the least key over all edges of GG between the two new sets. □\square

Invariant

Invariant I. At every moment, F⊆F∗F \subseteq F^*, and for every vertex xx of the current graph, the edges of FF inside the set of xx form a spanning tree of that set.

Lemma 1 (each added edge is in F∗F^*). Suppose line L6 extracts uu and adds the edge ee while the tree TT is growing. Let S⊆VS \subseteq V be the union of the sets of the vertices of TT. Then ee is the edge of least key of GG with exactly one end in SS, so e∈F∗e \in F^*.

Proof. The heap holds every vertex x∉Tx \notin T of HH that has an edge to TT, with the least key among the edges of HH from TT to xx: line L4 inserts the neighbours of v0v_0, and line L8 inserts or lowers each neighbour of each new vertex, which is the usual invariant of Prim's algorithm, here maintained by a Fibonacci heap. So the minimum of the heap is the edge of least key of HH with one end in TT. By Fact 2, the edges of GG with exactly one end in SS are the edges between the set of a vertex of TT and the set of a vertex outside TT, and the least key among them is carried by an edge of HH. So ee is the edge of least key of GG that leaves SS, and Fact 1 gives e∈F∗e \in F^*. □\square

Lemma 1 holds whether uu belongs to an earlier tree of the phase or not, and it does not depend on the heap limit kk. Since every edge added is in F∗F^*, which is a forest, no edge added closes a cycle with FF. When uu is new, ee joins uu to TT; when uu is in an earlier tree T0T_0, ee joins TT to T0T_0, and TT takes the label of T0T_0 at line L7. So, at the end of the phase, the vertices with one label are joined by the edges added in the phase, and together with the edges inside each old set they form a spanning tree of the new set. This keeps Invariant I through line L10.

Termination

Lemma 2. Every phase lowers the number of vertices that have edges by at least half.

Proof. Each tree starts at a vertex v0v_0 with an edge, so its heap is not empty, and the loop at line L5 runs at least once: the tree adds at least one edge before any stop. Either the first extracted vertex is new, and the tree has at least two vertices, or it belongs to an earlier tree, and v0v_0 joins that tree. Either way, every label that holds a vertex with edges holds at least two vertices of HH. □\square

So the number of phases is at most log⁡2n+1\log_2 n + 1, and the algorithm stops.

The result

Theorem. The algorithm returns F∗F^*, a minimum spanning forest of GG.

Proof. When the loop at line L1 stops, the current graph has no edges. By Fact 2, no edge of GG joins two different sets, so each set is a whole connected component of GG, or a single vertex with no edges. By Invariant I, FF has a spanning tree of each set and F⊆F∗F \subseteq F^*. So FF is a spanning forest of GG inside the spanning forest F∗F^*; both have n−cn - c edges, where cc is the number of components, so F=F∗F = F^*. ■\blacksquare

The bound on the number of phases

This part is about the running time, not about correctness. Let mm be the number of edges after the first cleaning, and let phase ii start with tit_i vertices and use the limit ki=22m/tik_i = 2^{2m/t_i}.

Lemma 3. After phase ii, at most 2m/ki2m / k_i labels hold a vertex that still has edges.

Proof. Take such a label, and its first tree TT of the phase. TT did not join an earlier tree, so it stopped because its heap was empty or held more than kik_i vertices. If the heap was empty, every edge at TT had its other end in TT, so TT is a whole component of HH, and after line L10 it has no edges, which is excluded. So the heap held more than kik_i distinct vertices, each joined to TT by its own edge of HH. These edges have an end in the label's set; each edge of HH has two ends, so the labels of this kind number less than 2m/ki2m / k_i. □\square

So ti+1≤2m/kit_{i+1} \le 2m / k_i (after dropping the vertices without edges), and ki+1=22m/ti+1≥2kik_{i+1} = 2^{2m/t_{i+1}} \ge 2^{k_i}. Starting from k1=22m/n≥2m/nk_1 = 2^{2m/n} \ge 2^{m/n}, an induction gives log⁡(i−1)ki≥m/n\log^{(i-1)} k_i \ge m/n for every phase ii that is reached. A phase with ki≥tik_i \ge t_i is the last one: no heap can hold more than kik_i vertices, so every tree grows to a whole component. Since ti≤nt_i \le n, this happens as soon as ki≥nk_i \ge n, and that holds once log⁡(i−1)n≤m/n\log^{(i-1)} n \le m/n. Hence the number of phases is at most β(m,n)+1\beta(m, n) + 1, where β(m,n)=min⁡{i:log⁡(i)n≤m/n}\beta(m, n) = \min\{i : \log^{(i)} n \le m/n\}, which is at most log⁡∗n\log^* n.

Back to Fredman-Tarjan algorithm