Proofs: van Emde Boas layout
These are the human proofs of van Emde Boas layout, at full length.
The van Emde Boas layout is a bijection with contiguous subtrees, and the search finds the predecessor full
This proof shows: correctness, termination.
We use the pseudocode of the page. A tree with levels has the nodes with and ; let be their number. For , the first bits of a -bit path are and the last bits are .
Lemma 1 (V1 and V2). For every , the map is a bijection from the nodes of the tree with levels onto . Moreover, in the recursion of POS, the nodes of the top tree map onto and the nodes of bottom tree onto the range , so each recursive subtree occupies a contiguous range.
Proof. By induction on . For there is one node, and line L1 maps it to 0. Let , and ; both are less than . The nodes with form a tree with levels, whose node is the same pair, and line L3 maps them by , a bijection onto by induction. The nodes with split by their first bits into trees; in tree , the node corresponds to the node of a tree with levels, and this correspondence is a bijection. Line L5 maps it to , which by induction runs over the range stated, bijectively. The ranges for are disjoint, follow each other, and follow the range of the top tree. Their union is , and . So POS is a bijection onto . The parts are contiguous at this level, and by induction inside each part.
POS ends: each call is on a tree with fewer levels.
Lemma 2 (V3). After BUILD, the node holds the key of in-order rank in the padded list, and the tree is a binary search tree with these keys.
Proof. In a complete binary tree with levels, the subtree of has nodes, and the subtrees of the nodes to its left at depth , together with the ancestors between them, account for the first ranks; the left subtree of has nodes. So its in-order rank is . Line L7 writes, by Lemma 1 at a distinct cell for each node, the padded key of that rank. Since the padded list is increasing, with at the end, all keys in the left subtree of a node have smaller ranks, so they are smaller, and all keys in the right subtree are larger, with the convention that is larger than every key and the cells of are compared as .
Lemma 3. PREDECESSOR returns the largest key at most , or none if there is none.
Proof. Let be the set of real keys at most , and its largest element if is not empty. We keep the invariant: at the start of each pass of line L9, either is , or is in the subtree of the current node , or is empty and is none; and is none or a key at most .
At the start, the current node is the root, whose subtree holds all keys, and is none.
Let be the key at the current node, read in line L10 at its position, which is right by Lemmas 1 and 2. If , then , and line L11 returns it. If , then , all keys in the left subtree are smaller than , so is or in the right subtree. Line L12 sets and moves to the right child; if is in the right subtree the invariant holds by the second case, and otherwise . If (including ), every key in the right subtree is larger than , so larger than ; so if was in the subtree of the current node, it is in the left subtree, and line L12 moves there. In all cases the invariant holds.
The loop ends after at most passes, since grows by one each time (line L13). When , the current subtree is empty, so either or is empty and is none, and line L14 returns the right answer. And only ever takes values that are keys, by line L12.
By Lemma 3, contains(k) is right, since is in the set exactly when its predecessor is . The I/O bound of a search follows from Lemma 1 (each recursive subtree is contiguous) by the argument on the cache-oblivious model page.