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 be a finite undirected graph with vertices and a real weight on each edge. Parallel edges and self-loops are allowed, weights may tie, and need not be connected. Order the edges by the pair . 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 . With all keys distinct, the MSF for the order is unique; call it .
We prove that the algorithm (lines L1 to L11 of the page) stops, and that the set it returns is .
Facts used
Fact 1 (the cut property for distinct keys). If is a set of vertices and is the edge of least key with exactly one end in , then . 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 stands for a set of vertices of , and these sets partition the vertices that still have edges. Every edge of stands for one edge of whose ends lie in two different sets, and it is the edge of least key among all edges of between those two sets. Every edge of with both ends in one set is a loop of 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 by the tree of this phase that holds it and merges their sets. An edge of between two new sets was, by induction, represented by an edge of 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 keeps the least key over all edges of between the two new sets.
Invariant
Invariant I. At every moment, , and for every vertex of the current graph, the edges of inside the set of form a spanning tree of that set.
Lemma 1 (each added edge is in ). Suppose line L6 extracts and adds the edge while the tree is growing. Let be the union of the sets of the vertices of . Then is the edge of least key of with exactly one end in , so .
Proof. The heap holds every vertex of that has an edge to , with the least key among the edges of from to : line L4 inserts the neighbours of , 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 with one end in . By Fact 2, the edges of with exactly one end in are the edges between the set of a vertex of and the set of a vertex outside , and the least key among them is carried by an edge of . So is the edge of least key of that leaves , and Fact 1 gives .
Lemma 1 holds whether belongs to an earlier tree of the phase or not, and it does not depend on the heap limit . Since every edge added is in , which is a forest, no edge added closes a cycle with . When is new, joins to ; when is in an earlier tree , joins to , and takes the label of 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 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 joins that tree. Either way, every label that holds a vertex with edges holds at least two vertices of .
So the number of phases is at most , and the algorithm stops.
The result
Theorem. The algorithm returns , a minimum spanning forest of .
Proof. When the loop at line L1 stops, the current graph has no edges. By Fact 2, no edge of joins two different sets, so each set is a whole connected component of , or a single vertex with no edges. By Invariant I, has a spanning tree of each set and . So is a spanning forest of inside the spanning forest ; both have edges, where is the number of components, so .
The bound on the number of phases
This part is about the running time, not about correctness. Let be the number of edges after the first cleaning, and let phase start with vertices and use the limit .
Lemma 3. After phase , at most labels hold a vertex that still has edges.
Proof. Take such a label, and its first tree of the phase. did not join an earlier tree, so it stopped because its heap was empty or held more than vertices. If the heap was empty, every edge at had its other end in , so is a whole component of , and after line L10 it has no edges, which is excluded. So the heap held more than distinct vertices, each joined to by its own edge of . These edges have an end in the label's set; each edge of has two ends, so the labels of this kind number less than .
So (after dropping the vertices without edges), and . Starting from , an induction gives for every phase that is reached. A phase with is the last one: no heap can hold more than vertices, so every tree grows to a whole component. Since , this happens as soon as , and that holds once . Hence the number of phases is at most , where , which is at most .