Proofs: LOUDS tree
These are the human proofs of LOUDS tree, at full length.
Correctness of the LOUDS navigation formulas full
This proof shows: correctness.
Let be the nodes in level order, the degree of , and . Call the code of the super-root and the code of .
Fact A. The code of starts at position and ends at . Each code ends with exactly one 0, and the codes of come first, so the -th 0 ends the code of and the -th 0 ends the code of .
Fact B. The -th 1 of stands for , meaning that it lies in the code of the parent of (with as the parent of ), and the 1s of one code stand for the children of that node in order. A breadth-first traversal appends the children of to its queue when it removes , in order; the queue therefore receives (the child of ), then the children of , then those of , and so on. Its output order, which is the level order, is the order of insertion. The 1s of are written in the same order: one for in the super-root's code, then one for each child of , then of , and so on. So the -th 1 written corresponds to the -th node inserted, which is .
DEGREE. By Fact A, the code of occupies positions to , and all of them but the last are 1s, so .
CHILD. Let . The bits before contain ones, since . The -th bit of the code of , for , is therefore the -th 1 of , and by Fact B it stands for , the -th child of . Line L2 rejects .
PARENT. For , let . By Fact B, lies in the code of the parent of , and because only has its 1 in the super-root's code. The 0s before are the final 0s of the codes that end before , which are those of ; the code of contains and ends after it. So and line L7 returns .
NEXT-SIBLING. The siblings of are the nodes whose 1s lie in the same code. If , that 1 is in the same code (a code has no 0 before its end), it is the -th 1, and by Fact B it stands for , the next child of the same parent. If , the code ends at and is the last child. The same argument with gives PREV-SIBLING for ; for , and the root has no siblings.
CHILD-RANK. With as above and , the code containing starts at , since the -th 0 is the last 0 before . The bits from there to are all 1s, and there are of them, which is the index of among its siblings.
Space. has bits for the super-root and bits for each , in total , since the degrees sum to the edges.