Proofs: Tango tree
These are the human proofs of Tango tree, at full length.
The number of preferred path changes in a tango tree is the interleave bound full
This proof shows: complexity, competitive-ratio.
Fix the reference tree and an access sequence . For a node , list the accesses with , the key interval of the subtree of , and label each if and otherwise. Let be the number of changes of label along this list, and , the interleave bound.
Lemma 1. The preferred child of after access is left if the last access in up to time is labelled , right if it is labelled , and none if there is none.
Proof. By the correctness proof, access changes the preferred children exactly of the nodes on the root-to- path of , which are the nodes with , and sets them to the side of : left for (including , by line L11), right for . That is the label of at .
Theorem 1. The number of L-R switches (changes of a preferred child from left to right or from right to left) over the whole sequence is exactly .
Proof. By Lemma 1, the preferred child of changes between left and right exactly when two consecutive accesses in have different labels, which is one change counted in . Sum over .
Theorem 2. Access visits at most paths, where is its number of L-R switches and the number of nodes that get their first preferred child during access . So the total number of paths visited is at most .
Proof. Each path visited after the first is entered from a pair of line L6, and then changes its preferred child: from the other side (an L-R switch) or from none (a first choice). Different pairs have different . A node gets its first preferred child only once. Sum and use Theorem 1.
Theorem 3 (cost). If each auxiliary tree is a red-black tree with depth fields, so that a search, a cut and a join on a path of at most nodes take time, then the total cost is , and so .
Proof. Each visited path costs one search, and each pair and line L11 cost one cut and one join, all in trees of nodes. By Theorem 2 the number of these is . Wilber's first lower bound, in the form proved by Demaine, Harmon, Iacono and Pătraşcu, is , and since each access touches a node. So .
The time bound of a search, cut and join in is the part this page does not prove; it is the standard cost of split and concatenate of red-black trees of size , with the depth fields used to find the range to cut, as in the paper of Demaine, Harmon, Iacono and Pătraşcu. In the Python code, the search is a binary search on a sorted list, with at most comparisons, and the tests check this count; the cut and the join are list slices.
Tango tree access finds the key and keeps the preferred paths full
This proof shows: correctness, invariant, termination.
Write for the reference tree, for the key interval of the subtree of in , and for the preferred child of (a child of or none). A path is a chain with and none or missing, where is the root of or a child that its parent does not prefer. The invariant (T1, T2) says the stored paths are exactly these chains, as sorted key sets, indexed by their tops.
Lemma 1. The paths partition the nodes of . For a path with top , all keys of lie in , and for each , the nodes of below are exactly the nodes of with keys in .
Proof. Each node is on exactly one path: follow parents up while the parent prefers the current node; the node where this stops is the top, and is on its chain. The keys of a chain from are in . The nodes below on the chain are in the subtree of , and the nodes are ancestors of , whose keys are not in .
Lemma 2 (exit node). Let be a path with top , with and not on . Let be the deepest node of with , and the child of on the side of . Then is the deeper of the predecessor and the successor of among the keys of , exists, is not preferred by , and is the top of a path with .
Proof. exists since . Say ; the other case is symmetric. Then for the left child of , which exists since holds . If , then is on and is deeper than with , which contradicts the choice of ; so is not preferred and is the top of a path. The nodes of in are and the nodes below , which are in by Lemma 1; that is the right subtree of (or empty). So no key of is in , and is the successor of on . The predecessor, if any, is a key of smaller than , hence outside , hence an ancestor of : shallower.
Termination and the result of the search. At the start, holds the root, and . By Lemma 2, each round of lines L5 to L7 moves to a path whose top has and is deeper than before. The depth is bounded, so the loop stops, and it stops only at line L4, when is on . The pairs recorded are exactly the nodes on the root-to- path of whose preferred child is not on the side of , with the child on the side of : on each path visited, the nodes of the root-to- path above have their preferred child toward (they are followed by the next node of , which is on the way to because is below them with ).
Updates. Take the pairs from the top down. Before the update for , the path that holds contains the root of (by induction: the first is on the root path, and each join adds the next path below the previous ). By Lemma 1, CUT removes exactly the nodes of that path below ; they form the chain from the old , whose parent will no longer prefer it, so they form a path with that top, as (T2) needs. JOIN adds the path with top , whose keys are in , a range that holds no other key of the upper part (it is in the subtree of , and the upper part has no node below now). After setting , the chain from the root follows and then the chain of , which is the joined path, and is no longer a top. So (T1) and (T2) hold after each pair. Line L11 does the same at with the left child. After the access, every node on the root-to- path has on the side of , and is left, which is the definition of preferred children after an access to ; all other preferred children are unchanged, as the definition requires, since the most recent access in their subtrees is unchanged.