Algorithm Search⌘K

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 −∞-\infty 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 vv and every ii, the ii-th rightmost active child cc of vv has rank(c)+ℓ(c)≥i−1\mathrm{rank}(c) + \ell(c) \ge i - 1.

(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 O(1)O(1) 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 xx below yy with key(y)<key(x)\mathrm{key}(y) < \mathrm{key}(x) keeps (H), and it keeps the second half of (B): an active xx goes before all children of yy, a passive xx after all of them.

Proof. The only new parent relation is yy above xx, and key(y)<key(x)\mathrm{key}(y) < \mathrm{key}(x). The subtree of xx moves as a whole, so all other parent relations are unchanged. The placement is the definition of link. □\square

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 zz below yy below xx with x<y<zx < y < z; 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 cc is removed from an active node vv, and then the rank of vv goes down by one and its loss goes up by one. Then (C) still holds at vv, at the parent of vv, and at every other node.

Proof. At vv: the active children right of cc keep their index, and those left of cc get an index one smaller, so their condition gets weaker. At the parent of vv: rank(v)+ℓ(v)\mathrm{rank}(v) + \ell(v) does not change, and the index of vv does not change. Nothing else changes. □\square

If vv is an active root, only its rank goes down. Then (C) at vv holds by the first half of the proof, and no condition is on vv itself, because its parent is passive. If vv is passive, nothing is subtracted, and no condition is on vv or on its children's ranks at vv.

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 xx, yy be active roots of rank rr. After the link, yy is an active child of the active xx, so it is no longer an active root, which is allowed. The rank of xx becomes r+1r + 1, which is its new number of active children. In xx, yy is the (r+1)(r + 1)-th rightmost active child, and rank(y)+ℓ(y)=r+0≥r\mathrm{rank}(y) + \ell(y) = r + 0 \ge r, so (C) holds. No other active child of xx changes its index. If the passive rightmost child zz of xx moves to the root, no active index changes. xx is still an active root with loss 0.

Root degree reduction. xx, yy, zz are linkable, so they have no active children. After the step, yy has no active child and zz is passive, so rank(y)=0\mathrm{rank}(y) = 0 is right; xx has the one active child yy, so rank(x)=1\mathrm{rank}(x) = 1 is right, and the condition for yy is 0+0≥00 + 0 \ge 0. xx 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. xx has loss at least 2, so by (B) it is not an active root, so its parent yy is active. Removing xx and the update of yy are the case of Lemma 2, or of the remark after it if yy is an active root. Then xx 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 xx.

Two-node loss reduction. xx and yy have loss 1 and rank rr, so neither is an active root, and the parent zz of yy is active. First yy is cut and linked below xx, the rank of xx goes to r+1r + 1, and both losses go to 0. In xx, yy is the (r+1)(r + 1)-th rightmost active child with r+0≥rr + 0 \ge r. At the parent of xx, rank(x)+ℓ(x)\mathrm{rank}(x) + \ell(x) goes from r+1r + 1 to (r+1)+0(r + 1) + 0, so it does not change. Then the rank of zz goes down by one and, if zz is not an active root, its loss goes up by one; with the cut of yy this is the case of Lemma 2. If z=xz = x, the net effect on xx is rank rr and loss 1, again with the sum r+1r + 1, so the parent of xx still sees no change. □\square

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 vv of larger key is linked below the other root uu, which keeps (H) by Lemma 1, and vv is passive. The active children of vv still have a passive parent. The root uu is passive. Insert is a meld.

Decrease-key (lines L6 to L9). Lowering key(x)\mathrm{key}(x) keeps (H) between xx and its children. If the new key is below the key of the root, the items of xx and the root are swapped; then the root has a key smaller than all others, and xx has the old key of the root, which is smaller than all keys in the subtree of xx, so (H) holds below xx. In both cases the only relation that may break (H) is between xx and its parent yy, and line L7 removes it by moving xx below the root, whose key is now the smallest. If xx is passive, no active index changes. If xx is an active root, the passive yy is not changed, and xx stays an active root. If xx and yy are active, line L8 is the case of Lemma 2 (or of the remark after it, if yy is an active root), and xx 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 xx of smallest key has the smallest key of all the remaining items. Line L10 makes xx passive, so its active children become active roots, and they get loss 0. Line L11 puts the other children of the old root below xx, which keeps (H) since xx 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 xx, which keeps (H). Line L13 and line L14 are transformations. □\square

Lemma 5 (termination). The loop of line L14 ends after at most 2deg⁡(root)+3a2 \deg(\text{root}) + 3a rounds, where aa is the number of active roots when it starts.

Proof. Let P=2deg⁡(root)+3aP = 2 \deg(\text{root}) + 3a. An active root reduction removes one active root and adds at most one child to the root, so PP drops by at least 3−2=13 - 2 = 1. A root degree reduction removes three children of the root, adds one, and adds one active root, so PP drops by 6−2−3=16 - 2 - 3 = 1. Since P≥0P \ge 0, the loop ends. Each other operation does a fixed number of transformations. □\square

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 −∞-\infty, after which the item is at the root, followed by delete-min. ■\blacksquare

Back to Strict Fibonacci heap