Proofs: Strict Fibonacci heap
These are the human proofs of Strict Fibonacci heap, at full length.
The strict Fibonacci heap operations keep heap order and the structure invariant I1 full
This proof shows: correctness.
We use the definitions of the page. Every key is treated as distinct (ties are broken by the order of insertion), and is smaller than every key. We prove the following, for the operations of the pseudocode.
- (H) Heap order. Every node has a larger key than its parent.
- (B) Bookkeeping. The root is passive. Every active node has rank equal to its number of active children. The active children of every node come before its passive children. Every active root has loss 0.
- (C) The rank condition. For every active node and every , the -th rightmost active child of has .
(B) and (C) are the parts of I1 that the code keeps; the part of I1 that puts the linkable children of the root at its right end is only needed to find them in time, and the code does not use it. The invariants I2 to I4 are proved in Section 5 of the paper and are not proved here.
Lemma 1 (links). A link of below with keeps (H), and it keeps the second half of (B): an active goes before all children of , a passive after all of them.
Proof. The only new parent relation is above , and . The subtree of moves as a whole, so all other parent relations are unchanged. The placement is the definition of link.
Every link in the code is of this kind: the active root and the two-node loss reductions link the node of larger key below the one of smaller key; the root degree reduction links below below with ; and every other link puts a node below the root or below the new root of delete-min, which by the lemmas below has the smallest key in the heap.
Lemma 2 (the effect of a lost child on (C)). Suppose an active child is removed from an active node , and then the rank of goes down by one and its loss goes up by one. Then (C) still holds at , at the parent of , and at every other node.
Proof. At : the active children right of keep their index, and those left of get an index one smaller, so their condition gets weaker. At the parent of : does not change, and the index of does not change. Nothing else changes.
If is an active root, only its rank goes down. Then (C) at holds by the first half of the proof, and no condition is on itself, because its parent is passive. If is passive, nothing is subtracted, and no condition is on or on its children's ranks at .
Lemma 3 (the transformations). Each of the four transformations keeps (H), (B) and (C), and keeps the set of nodes.
Proof. (H) and the placement of children hold by Lemma 1. No node is created or deleted.
Active root reduction. Let , be active roots of rank . After the link, is an active child of the active , so it is no longer an active root, which is allowed. The rank of becomes , which is its new number of active children. In , is the -th rightmost active child, and , so (C) holds. No other active child of changes its index. If the passive rightmost child of moves to the root, no active index changes. is still an active root with loss 0.
Root degree reduction. , , are linkable, so they have no active children. After the step, has no active child and is passive, so is right; has the one active child , so is right, and the condition for is . is a child of the passive root, so it is an active root, and its loss is 0. The rank of the root is not used, since the root is passive.
One-node loss reduction. has loss at least 2, so by (B) it is not an active root, so its parent is active. Removing and the update of are the case of Lemma 2, or of the remark after it if is an active root. Then is linked below the passive root with loss 0, which makes it an active root with loss 0, as (B) needs; no condition is on .
Two-node loss reduction. and have loss 1 and rank , so neither is an active root, and the parent of is active. First is cut and linked below , the rank of goes to , and both losses go to 0. In , is the -th rightmost active child with . At the parent of , goes from to , so it does not change. Then the rank of goes down by one and, if is not an active root, its loss goes up by one; with the cut of this is the case of Lemma 2. If , the net effect on is rank and loss 1, again with the sum , so the parent of still sees no change.
Lemma 4 (the operations). Insert, meld, decrease-key and delete-min keep (H), (B) and (C), and the root holds the smallest key.
Proof. By (H), the root of a tree has its smallest key. The transformations are covered by Lemma 3; it remains to check the other steps.
Meld (lines L2 to L4). All nodes of the smaller tree become passive, so no condition of (B) or (C) is on them, and the active nodes of the larger tree keep their children. The root of larger key is linked below the other root , which keeps (H) by Lemma 1, and is passive. The active children of still have a passive parent. The root is passive. Insert is a meld.
Decrease-key (lines L6 to L9). Lowering keeps (H) between and its children. If the new key is below the key of the root, the items of and the root are swapped; then the root has a key smaller than all others, and has the old key of the root, which is smaller than all keys in the subtree of , so (H) holds below . In both cases the only relation that may break (H) is between and its parent , and line L7 removes it by moving below the root, whose key is now the smallest. If is passive, no active index changes. If is an active root, the passive is not changed, and stays an active root. If and are active, line L8 is the case of Lemma 2 (or of the remark after it, if is an active root), and becomes an active root with loss 0.
Delete-min (lines L10 to L14). By (H) every node other than the root is in the subtree of a child of the root, so the child of smallest key has the smallest key of all the remaining items. Line L10 makes passive, so its active children become active roots, and they get loss 0. Line L11 puts the other children of the old root below , which keeps (H) since has the smallest key; active nodes among them stay active roots. Line L12 moves only passive children, so no active index changes, and they go below , which keeps (H). Line L13 and line L14 are transformations.
Lemma 5 (termination). The loop of line L14 ends after at most rounds, where is the number of active roots when it starts.
Proof. Let . An active root reduction removes one active root and adds at most one child to the root, so drops by at least . A root degree reduction removes three children of the root, adds one, and adds one active root, so drops by . Since , the loop ends. Each other operation does a fixed number of transformations.
Theorem. Every operation ends, the root always holds the smallest key, find-min returns it, delete-min removes and returns it and keeps all other items, and insert, meld, decrease-key and delete change the set of items as the abstract type says.
Proof. Termination is Lemma 5. By Lemma 4, (H) holds after every operation, so find-min returns the smallest key. Delete-min removes only the old root, whose key was the smallest; by Lemma 4 it keeps every other node, and the new root holds the smallest remaining key. Insert adds one node, meld takes the union of the two node sets, and decrease-key changes one key and moves nodes but removes none; the swap of items keeps the set of (item, key) pairs, and the handle of each item follows it to its new node. Delete is decrease-key to , after which the item is at the root, followed by delete-min.