Proofs: Kinetic heap
These are the human proofs of Kinetic heap, at full length.
The kinetic heap reports the minimum at every time, and processes exactly Φ events in the worst case full
This proof shows: correctness.
We use the definitions of the page. Each item has the key . The order just after time is: if , or and . Write if or the two keys and slopes are equal. The invariants at the end of each operation are (I1) for every ; (I2) every position has a current certificate whose failure time is as defined on the page, and every finite one is larger than .
Lemma 1 (a certificate). Let and be two items with . If , then for all . If , let ; then , exactly for , and .
Proof. The difference is linear, and . If , it does not decrease, so for . If , it decreases and has its only zero at . Since , , and exactly when . At the keys are equal and , so .
Lemma 2 (between events). If (I1) and (I2) hold at time and no finite failure time is in , then has a smallest key at every time in , and (I1) and (I2) hold at time .
Proof. By Lemma 1, for each edge either the certificate never fails, or it fails after ; in both cases the parent key is at most the child key at all times in . Then by induction on the depth, for all and all such . For (I1) at time : if , the keys at are in order and, if equal, the slopes are in order. If , the failure time is larger than , so . The certificates depend only on the items at the positions, which do not change, so (I2) holds, with all finite failure times larger than .
Lemma 3 (an event). Suppose that before line L5 the heap satisfies for every edge except possibly the edges whose certificates have failure time , and every such edge has with equal keys. Process one of them at position . Afterwards the same statement holds, with one edge less of this kind or with new ones only of the same kind, and every certificate is correct.
Proof. Let be the item at and the item at ; by Lemma 1, and . After the swap, is at and at , and , so the edge from to is in order, and its certificate never fails. The edges that changed their items are those at and at ; line L6 computes their certificates again. The edge from to its other child : before, or the edge was a failing one; now is the parent, with and , so if then . The edges from to its children : before, or a failing edge; now is the parent, and the new certificate is computed by line L6; if , the edge has failure time by the formula (the keys of and are equal at , so , and means equality and ). The edge above : the parent had ; now the child is , with the same key as at ; if , then the keys are equal and the slope of is smaller, so the failure time is . In all cases an edge is either in order just after , or has failure time with equal keys, as claimed.
Lemma 4 (the potential). Let be the number of pairs of items such that is at a proper ancestor of the position of and . Each event lowers by at least 1. So, if no item is inserted or deleted, ADVANCE processes at most events, and this is at most .
Proof. This is Lemma 2 of da Fonseca and de Figueiredo, written for a min-heap. Let the event swap at and at , with . Let be the other child of . Split the other items into three sets. For an item that is not in the subtree of , its set of descendants is the same set of items before and after, and so is its set of ancestors. For an item in the subtree of below , its ancestors are the same set of items: and just exchange places. For an item in the subtree of , the ancestor is replaced by ; the pair counts after only if , which implies , so the count for does not grow. The pairs with or as the descendant: the ancestors of are ancestors of both before and after. The pairs with or as the ancestor are covered by the cases above, except the pair of and itself: before, is above and , so it counts; after, is above and is false, so it does not. So drops by at least 1. It is never negative, so the number of events is at most its initial value. Each item at depth is in at most pairs as the descendant, so .
Lemma 5 (the lower bound). For , , and a start time , ADVANCE to processes exactly events.
Proof. , so at time the item with the smallest key is the one with nearest to . At this is the item alone, so every item is at the root at some time in . An event moves one item up by one level and one item down. So an item that starts at depth needs at least events in which it moves up, and these are different events for different items. So there are at least events, and by Lemma 4 at most .
Theorem. After each operation, (I1) and (I2) hold, and FIND-MIN returns an item with the smallest key at time . With no inserts and deletes, the number of events is at most , and this is tight.
Proof. INSERT and DELETE are the usual sift operations of a binary heap under the order , so (I1) holds after them, and lines L10 and L12 compute the certificate of every edge whose items changed; by Lemma 1 every finite failure time is at least , and it equals only if the child is before the parent in , which (I1) excludes. So (I2) holds. In ADVANCE, the loop takes the earliest failure time . By Lemma 2 the heap is valid up to . By Lemma 3, after the events at time that the loop processes, every edge is in order just after or has failure time ; the loop goes on while there is one with failure time , and by Lemma 4 the number of events is finite, so the loop leaves time with (I1) and (I2) at . Then Lemma 2 applies again up to the next failure time or . When the loop ends, Lemma 2 gives (I1) and (I2) at , and by (I1) and induction on depth, has a smallest key at . The bound on the events is Lemma 4 and its tightness is Lemma 5; the depth of each of the positions is at most .