Proofs: Violation heap
These are the human proofs of Violation heap, at full length.
The violation heap operations keep heap order, the rank rule and the size bound full
This proof shows: correctness.
We use the definitions of the page. A child is active if it is one of the last two children of its parent. A missing child has rank , and for a node with active children , . The invariants are (1) heap order: every key is at least the key of its parent; (2) the rank rule: for every node .
Lemma 1 (the pointers). If the sibling lists are as in the representation, then for an active node the procedure of lines L11 and L16 returns the parent of , and for a node that is not active it returns NIL.
Proof. Let . If is the last child of , then and . If is the second child from the end, is the last child, so and . If is an older child, and are siblings of , and neither is the last child of the other, since a last child is in the subtree of its parent and siblings are not. For a root, $y = $ NIL.
Lemma 2 (heap order). Every operation keeps (1), and holds a smallest key.
Proof. Insert and meld add roots. In JOIN3, line L1 puts the root of smallest key on top, and the two others become its children, so their keys are at least its key; nothing else changes. In delete-min, the children of become roots, which removes the parent relation and so cannot break (1). In decrease-key, the new key of a root has no parent to compare with. If line L11 returns, is active and its new key is at least the key of its parent, and the children of had keys at least the old key of , which is at least the new key. Otherwise becomes a root, which keeps (1) for and its children. The node , a child of , has a key at least the old key of , which was at least the key of the old parent of ; so in the place of keeps (1). By (1), the root of each tree holds the smallest key of the tree, and every operation sets to a smallest root, either by a comparison with the new root or by a scan of all roots.
Lemma 3 (the rank rule). Every operation keeps (2).
Proof. First, for every node, and every rank that the code sets is , of a node, or one more than an old rank. So all ranks stay .
depends only on the active children of and their ranks. We list the events that change these, and for each we show that (2) holds for at the end.
- A join on (line L3). Before it, . After it, and are the active children of , so . Line L2 changes the order of two children that are no longer active after line L3, so it does not matter for .
- The children of change at line L13. There are two cases. If , line L14 sets after the change. If is the parent of and was not active, the last two children of do not change: was older than both of them, and its place either gets or goes away. If is the parent of and was active, then at line L11, and the loop of line L15 first looks at .
- The rank of an active child of goes down. Ranks go down only at line L16 (at line L14, the node is a root). Line L16 lowers and, if is active, sets to its parent, which by Lemma 1 is . So the loop looks at next.
- The rank of goes up. This happens only in a join, which is the first case, and at line L14, where it is set equal to .
When the loop of lines L15 and L16 looks at a node , it either finds , so (2) holds at and did not change, so no parent sees a change; or it sets , so (2) holds at , and the change of is an event for the parent of , which is looked at next if is active and does not matter if is not active. The loop goes up one level each time, so it ends. In delete-min and insert no non-root changes its active children, and a node that becomes a root keeps its children. So when an operation ends, every node obeys (2).
Lemma 4 (the paper's Lemma 3). Let obey (2), and let its active children have ranks , with for a missing child. Then , or and .
Proof. Since , . If , then , which needs , that is .
Theorem (size bound). If every node obeys (2), the subtree of a node of rank has at least nodes, where and . So no rank is more than , with .
Proof. By induction on the height of the subtree. Let have rank and active children of ranks . If , the subtree has node. Let . By Lemma 4, , so has an active child of rank . If , that child alone has at least nodes by induction, so has more. Otherwise and . If , the two children give at least nodes. If , then , so and , and with its child gives at least nodes. In every case the bound holds. Since , a heap of nodes has no rank above .
Theorem (the operations are correct). Find-min returns a smallest key, delete-min removes and returns a smallest key, and the other operations keep the multiset of keys as the abstract type says.
Proof. By Lemma 2, is a root with a smallest key, which find-min returns. Delete-min removes exactly the node and keeps all other nodes, since its children become roots and the joins only move roots below roots. Insert adds one node, meld takes the union of the node sets, and decrease-key changes only the key of and moves subtrees, so no node is lost. By Lemmas 2 and 3 the invariants hold after each operation, so the next operation starts from a valid heap.