Binary Search Trees in Lean Check a result Declarations Bibliography Lean source

Chapter 39Saving trees in their nodes

The combination of Chapter 29 runs two online BST algorithms in alternating rounds, and every round starts from the same initial tree TT. At the end of a round, the structure must turn whatever tree the interrupted algorithm left behind back into TT. A BST cannot keep a second copy of TT on the side. Demaine, Iacono, Langerman and Özkan (2013) therefore store TT inside the tree itself, in the O(log⁡n)O(\log n) bits of data that every node may carry: their tree state buffer (Section 3 of their paper).

  • Section 39.1 formalizes the buffer: one data cell per node, indexed by inorder rank, and a finger that walks from cell to cell while another finger rotates the tree. Its headline is the paper’s Lemma 9: an inorder scan interleaved with rr rotations costs at most 4n+3r4n + 3r.
  • Section 39.2 saves a tree into the cells of its own nodes, at twelve bits per node, and restores it from any tree of the same size. Both take linear time: at most 72n72n to save and 56n56n to load, the paper’s Lemma 10.

Most of this chapter is proof machinery. The exception is the node and shared-node layers at the end of Section 39.1: the combined policy of Chapter 29 carries a shared tree, so their definitions are on the reading paths of the combination theorems. The note at the start of that section says what a reader needs from them.