Proofs: LOUDS trie
These are the human proofs of LOUDS trie, at full length.
The LOUDS formulas find the children and the parent of a node, and the LOUDS trie answers membership correctly full
This proof shows: correctness, complexity.
We use the pseudocode, the notation and the invariant (L1) to (L4) of the page. Let be the number of children of node , and .
Lemma 1 (breadth-first numbering). The children of node are the nodes , in order of their labels.
Proof. Breadth-first order with a queue visits the nodes in the order they are enqueued, and the children of each node are enqueued, in label order, when the node is visited. The root is node 0, and the nodes enqueued before the children of are the root and the children of nodes , which are nodes.
Lemma 2 (layout). . Before the group of there are zeros (the zero of and the closing zeros of nodes ) and ones.
Proof. By construction, the group of follows the prefix and the groups of nodes , each closed by one 0. Counting the bits of these parts gives the claim.
CHILDREN. By Lemma 2 the -th 0 is the bit just before the group of , and the -th 0 closes it. So and delimit the group, and . The number of 1s before is , so and . By Lemma 1 these are the children of .
PARENT. Let be a child of . The 1s of are, in order, the leading 1 and the groups of nodes ; by Lemma 1 the -th 1 of the groups, for , is node . So the -th 1 of lies in the group of , at position . By Lemma 2 there are exactly zeros before any position of the group of , so .
CHILD and CONTAINS. By (L3) the labels are distinct and sorted, so the binary search finds the child with label if it exists, and reports NIL otherwise. CONTAINS starts at the root, whose string is empty, and line L5 keeps the claim that is the node whose string is the part of read so far: CHILD returns the child by the next symbol, whose string extends it by that symbol. If some child is missing, no node spells the read part, and since every key is the string of a node (the pointer trie built at line L7 has a node for each prefix of each key), is not a key. If the walk ends, spells , and by construction is set exactly when is a key.
Complexity. CHILDREN and PARENT use two select or rank operations, which take time with a constant-time index. CHILD adds a binary search over at most labels, . CONTAINS makes calls of CHILD, . has ones and zeros, so bits.