Proofs: Holm-de Lichtenberg-Thorup algorithm
These are the human proofs of Holm-de Lichtenberg-Thorup algorithm, at full length.
The Holm-de Lichtenberg-Thorup algorithm keeps a spanning forest full
This proof shows: correctness.
We prove that after every operation is a spanning forest of the current graph , so that line L12 answers correctly. We prove it together with the invariants of the page. Write for the graph of edges of level at least , for the set of tree edges, and .
- (I0) is a forest, every edge of is an edge of , and .
- (I1) For every non-tree edge of level , the ends of are connected in .
- (I2) Every tree of has at most vertices.
We first show that (I0) and (I1) are enough for the claim.
Lemma 1. If (I0) and (I1) hold, then for every , is a spanning forest of , and in particular is a spanning forest of .
Proof. and is a forest by (I0). Every edge of is either in or a non-tree edge of level , whose ends are connected in by (I1). So every edge of has its ends in one tree of , and has the same components as .
So it suffices to prove that every operation keeps (I0), (I1) and (I2). They hold for the empty graph.
Lemma 2 (insertion). INSERT keeps (I0), (I1) and (I2).
Proof. If and are in different trees of , line L2 adds at level 0. Then stays a forest, and only changes. Its new tree joins two trees, but (I2) at level 0 only asks for at most vertices. Non-tree edges keep their levels and their paths in only grow. Otherwise is a non-tree edge of level 0 whose ends are connected in , so (I1) holds for it, and the forests do not change.
Lemma 3 (deleting a non-tree edge). Line L3 keeps the invariants.
Proof. The forests do not change, and (I1) is a statement about each remaining non-tree edge separately.
Now let be a tree edge of level that is deleted. Line L4 removes from , so loses for and is unchanged for . For each let and be the trees of that contain and ; they are the two halves of the tree of that contained .
Lemma 4. Before the search, (I0) and (I2) hold, and (I1) holds for every non-tree edge except possibly those whose ends lie in different halves and at their level .
Proof. Removing an edge keeps a forest a forest and makes trees smaller. A non-tree edge of level had its ends connected in . If , then did not change. If and the path in between the ends of did not use , it is still there. If it used , the ends of lie one in and one in .
Call a non-tree edge crossing at level if it has level and its ends are one in and one in . Note that and , since .
Lemma 5 (the loop at level ). Suppose the loop of lines L5 to L10 starts level and, at that moment, (I0) and (I2) hold, (I1) holds for every non-tree edge of level greater than , and there is no crossing edge at any level greater than . Then either the iteration ends at line L9 with all invariants restored, or it ends with no crossing edge at level , (I0) and (I2) hold, and (I1) holds for every non-tree edge of level at least .
Proof. Line L6 names and , which are and in some order; relabel so that is the smaller. Since is the vertex set of one tree of before the cut, (I2) gives , so .
Line L7. The tree edges of level in rise to level and are linked in . All edges of now have level at least , so is a single tree of , made of the trees of inside joined by the raised edges. It has at most vertices, so (I2) holds at level . Other trees of are unchanged. itself does not change, so (I0) holds. Raising tree edges only adds edges to , so (I1) still holds for every edge for which it held.
Lines L8 to L10. Take a non-tree edge of level with an end in and let be the other end. If is not crossing at level , then by Lemma 4 its ends are connected in , so . If is crossing, then . So the test of line L9 is true exactly for crossing edges.
If , line L10 raises to level . Its ends are in , which is a tree of , so (I1) holds for . Nothing else changes.
If , line L9 makes a tree edge of level and links it in . Then stays a forest, because joins and (in some order), which are different trees of . So (I0) holds. For (I2), changes only for , where its tree is joined again by ; this tree has vertex set equal to that of the tree of that held , which had at most vertices. For (I1), take any non-tree edge of level . If , (I1) held by assumption or by the steps above. If , then in the halves and are joined again by , and every other tree of is unchanged, so the ends of , which were in one tree of before was cut, are in one tree again. So all invariants hold, and the deletion ends.
If the scan ends without line L9, every non-tree edge of level with an end in has been raised, so no crossing edge of level is left; one crossing at level would have an end in and would have been found. Every remaining non-tree edge of level is not crossing, so (I1) holds for it by Lemma 4, and the raised edges satisfy (I1) as shown.
Lemma 6. A non-tree edge of level is never crossing.
Proof. Its level is greater than the level of , so did not contain , and by (I1) before the deletion its ends are connected in for every , so they lie in one tree of . Raising edges during the search moves edges to level at most with both ends in one tree of , so this stays true.
Theorem. After every operation, (I0), (I1) and (I2) hold, so is a spanning forest of and CONNECTED is correct.
Proof. By induction on the operations. Insertions and deletions of non-tree edges are Lemmas 2 and 3. For the deletion of a tree edge of level , Lemmas 4 and 6 give the assumption of Lemma 5 at , and each iteration of Lemma 5 that does not return gives the assumption for . If some iteration returns at line L9, the invariants hold. Otherwise, after level 0, there is no crossing edge at any level, (I0) and (I2) hold, and (I1) holds for every non-tree edge. In that case no edge of joins and : tree edges do not, since and are different trees of , and a non-tree edge of level has its ends connected in by (I1), so both ends lie in one tree of . So the component of is split in as in (line L11). By Lemma 1, is a spanning forest of , and and are connected in exactly when they are in one tree of .