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

Part III · Classical search trees · NotesBibliographic notes

These notes say where the results of this part come from. Knuth’s volume on sorting and searching (Knuth 1998) and Mehlhorn’s textbook (Mehlhorn 1984) cover most of the classical material in more depth.

Static trees

Chapter 19 studies trees that never change.

The optimal static tree for given access frequencies goes back to Gilbert and Moore (1959), who computed it by dynamic programming in O(n3)O(n^3) time, for the case where only the gaps between keys carry weight. Knuth (1971) treated the general problem and observed that optimal roots are monotone, which brings the time down to O(n2)O(n^2). Yao (1980) isolated the reason: the quadrangle inequality on the weights implies monotone optimal choices for a whole family of dynamic programs.

When only the gaps carry weight, the problem is that of optimal alphabetic codes. Hu and Tucker (1971) solved it in O(nlog⁡n)O(n \log n) time. The algorithm of Garsia and Wachs (1977) computes a tree of the same cost by a simpler procedure, with the same running time.

Near-optimal trees are easier to build. Mehlhorn (1975) chose each root by bisecting the weight, built the tree in linear time, and bounded its cost by a constant times the entropy plus a constant. Mehlhorn (1977) gave the best possible bound on the weighted path length in terms of the entropy, with an additive constant only. Larmore (1987) computed approximately optimal trees in subquadratic time. These entropy bounds are the ones the book proves in Chapter 14.

Weights can also change. Mehlhorn (1979) maintained nearly optimal trees under changing frequencies, and the biased search trees of Bent et al. (1985) keep every key xx at depth O(log⁡(W/wx))O(\log(W/w_x)) under insertions, deletions, joins and splits.

Rank-balanced trees

Chapter 20 presents AVL, red-black and WAVL trees as one theory of ranks.

AVL trees are the first balanced search trees (Adel'son-Vel'skiĭ and Landis 1962). Bayer (1972) introduced symmetric binary B-trees, the binary form of 2-3-4 trees, which are B-trees of order 4 (Bayer and McCreight 1972). Guibas and Sedgewick (1978) recast them with red and black colours and gave a common framework for several balance conditions. The half-balanced trees of Olivié (1982) are another formulation of the same idea.

Tarjan (1983) showed that red-black trees can be updated with O(1)O(1) rotations per insertion or deletion, against Θ(log⁡n)\Theta(\log n) in the worst case for AVL deletion. Huddleston and Mehlhorn (1982) proved that the amortized number of rebalancing steps in suitable (a,b)(a,b)-trees is constant, which also gives red-black trees O(1)O(1) amortized recolourings. Andersson (1993) simplified the case analysis of red-black trees with what are now called AA trees.

Haeupler et al. (2015) introduced rank-balanced trees and the WAVL rule. A WAVL tree with no deletions is an AVL tree, it is always a red-black tree, and it uses at most two rotations per update. Sen et al. (2016) showed that a tree can skip rebalancing on deletion entirely and still keep its height logarithmic in the number of insertions.

Weight-balanced trees

Chapter 21 keeps subtree sizes in proportion.

Trees of bounded balance, BB[α], are due to Nievergelt and Reingold (1973). Blum and Mehlhorn (1980) corrected the range of parameters for which rotations restore the balance, and proved that the average number of rebalancing operations per update is constant.

Partial rebuilding replaces rotations by rebuilding a whole subtree. Andersson (1989) used it with simple balance criteria, and the scapegoat trees of Galperin and Rivest (1993) store no balance information in the nodes at all. Both achieve O(log⁡n)O(\log n) amortized update time.

Rebuilding a subtree into a perfectly balanced one takes linear time and constant extra space. The method of Day (1976) was improved by Stout and Warren (1986); it is now known as the Day–Stout–Warren algorithm. It first turns the tree into a path, a vine, and then compresses the vine by rotations.

Random trees

Chapter 22 shows that random insertion orders, treaps and randomized BSTs all draw from one distribution.

Hibbard (1962) analysed the BST built by inserting keys in random order, and showed that the expected cost of a search is about 2ln⁡n2 \ln n. The height is larger. Pittel (1984) showed that it grows like cln⁡nc \ln n almost surely, and Devroye (1986) identified the constant, c≈4.311c \approx 4.311. Reed (2003) and Drmota (2003) determined the next term of the expected height and showed that its variance is bounded.

Treaps are due to Aragon and Seidel; the journal version is Seidel and Aragon (1996). The same trees appear earlier as the Cartesian trees of Vuillemin (1980). A treap with random priorities is a random BST, and an update makes fewer than two rotations in expectation. The randomized BSTs of Martínez and Roura (1998) store subtree sizes instead of priorities and keep the distribution of a random BST after every insertion and deletion. Zip trees (Tarjan et al. 2021) are treaps whose ranks are geometric random variables, updated by unzipping and zipping paths instead of rotating; they are isomorphic to the skip lists of Pugh (1990). Gila et al. (2026) refine them to make the depth smaller and to support biased and persistent variants.

Insertions and deletions

Chapter 6 adds insertions and deletions to the model of Part I. The amortized bounds for splay trees with updates are in Sleator and Tarjan (1985). Level-linked trees support finger searches and updates near a finger in time logarithmic in the distance (Brown and Tarjan 1980; Huddleston and Mehlhorn 1982), and Hoffmann et al. (1986) used them for linear-time Jordan sorting.

Rotation distance

Every tree on nn keys can be turned into every other one with a bounded number of rotations. Culik and Wood (1982) showed that 2n−22n - 2 rotations suffice. Sleator et al. (1988) improved the bound to 2n−62n - 6 for n≥11n \ge 11, and proved, with hyperbolic geometry, that it is tight for all large nn. Pournin (2014) gave a combinatorial proof that it is tight for every n≥11n \ge 11. The graph of rotations between trees on nn keys has a Hamiltonian cycle (Lucas 1987). Computing the rotation distance between two given trees is fixed-parameter tractable in the distance (Cleary and St. John 2009); no polynomial-time algorithm is known, and the problem is not known to be NP-hard.