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

Part I · Models · NotesBibliographic notes

The models of this part come from several papers, each of which fixed the model it needed. The book follows the conventions of the papers it formalizes and proves the correspondences between them in Chapter 12.

Trees, rotations and accesses

Binary search trees and rotations are classical; see Knuth (1998) for their history. The rotation distance between two trees on nn keys is at most 2n−22n - 2 (Culik and Wood 1982), at most 2n−62n - 6 for n≥11n \ge 11, and this bound is tight for all large nn (Sleator et al. 1988). Pournin (2014) gave a combinatorial proof that it is tight for every n≥11n \ge 11. The library proves the simpler bound 2n2n in Chapter 3. The rotation graph is Hamiltonian (Lucas 1987), and computing the rotation distance is fixed-parameter tractable (Cleary and St. John 2009); whether it can be computed in polynomial time is open. For search trees on a tree, which generalize BSTs, the largest rotation distance is Θ(nlog⁡n)\Theta(n \log n) in the worst case (Cardinal et al. 2018).

The root-access model, in which each request rotates the requested key to the root, is the model of Wilber (1989) and of the splay tree paper (Sleator and Tarjan 1985). Allen and Munro’s move-to-root rule (Allen and Munro 1978) is its simplest algorithm.

Online algorithms and dynamic optimality

The dynamic optimality conjecture is stated in the splay tree paper (Sleator and Tarjan 1985): splaying is within a constant factor of the best offline execution on every sequence. The surveys of Iacono (2013) and of Chalermsook et al. (2016) describe what is known. Blum et al. (2003) showed that a BST that is allowed unlimited computation between accesses can be dynamically search-optimal: its search cost, though not its rotation cost, is within a constant factor of the offline optimum.

No polynomial-time algorithm is known that computes the offline optimum of a given sequence, and the problem is not known to be NP-hard.

The pointer machine and touched regions

The single-cursor pointer machine of Chapter 7 is the standard BST model of the literature, stated precisely by Demaine et al. (2009). Derryberry’s thesis (Derryberry 2009) compares the variants of this model used in the literature and shows that they agree up to constant factors. The touched-region accounting of Chapter 8 is the one used by Demaine et al. (2009) and in most later work on dynamic optimality.

The geometric view

The geometric view of Chapter 9 is due to Demaine et al. (2009), who showed that BST executions correspond to arborally satisfied point sets, up to constant factors. Derryberry et al. (2005) found a closely related formulation independently, in their framework for lower bounds. The PhD theses of Harmon (2006) and Kozma (2016) develop the geometric view further; the second also covers pattern-avoiding sequences. Kozma and Saranurak (2016) relate BST executions to flips between rectangulations, and Blelloch and Dobson (2023) show that many sorting algorithms correspond to offline BST executions in the geometric view.

Many fingers and linked searches

Executions with several persistent fingers (Chapter 10) are simulated by a single cursor in Demaine et al. (2013). Chalermsook et al. (2018) show that the offline optimum with kk fingers can be matched by a single root finger with an O(log⁡k)O(\log k) factor overhead, which is tight, and give randomized online BSTs within a further (log⁡k)O(1)(\log k)^{O(1)} factor, using techniques from the kk-server problem. The linked-search model of Chapter 11 is the model of the multiple-tree structure of Bose et al. (2016), Theorem 9; it is a pointer machine whose memory holds many trees, not a BST.

Real-world implementations

The pointer machine is due to Tarjan (1979), who used it for lower bounds on disjoint-set union. Bose et al. (2012a) observe that almost all BST implementations work on a pointer machine with O(1)O(1) words of balance information per node and O(1)O(1) working variables, and generate their operations in time proportional to the BST cost, and they show that their deamortization preserves these properties for algorithms with suitable amortized bounds (their Theorem 7). Demaine et al. (2013) define real-world BSTs, crediting Bose et al. (2012a), by the space conditions alone: O(1)O(1) registers of O(log⁡n)O(\log n) bits and O(log⁡n)O(\log n) bits per node. They prove that ComboBST and the one-finger simulation of several fingers preserve this property. The machine of Chapter 13 and its compiler are the library’s own.

How the models agree

The equivalence of the rotation model, the pointer machine and the geometric view, up to constant factors, combines Demaine et al. (2009) and Derryberry (2009). The constants proved in Chapter 12 are the library’s own.