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

Part IIBounds

Part I fixed what a BST execution is and what it costs. Part II asks how much a request sequence must or may cost, independently of any algorithm. Two kinds of statements live here. Upper-bound benchmarks are explicit functions of the sequence, such as the entropy of its access frequencies, that a good algorithm should match. Lower bounds hold for every execution, hence for the offline optimum. Algorithms enter only in Part III and Part IV, where each is measured against both.

  • Chapter 14 defines the classical benchmarks of the splay-tree literature: the working set, static optimality, the static and dynamic finger sums, the unified charge, and comparison with a fixed tree. It proves the implications between them, and the entropy bounds that make “static optimality” mean what its name says.
  • Chapter 15 studies a static tree searched with a lazy finger, where each search starts where the previous one ended, and proves that the best such tree costs, up to constant factors, the best weighted dynamic finger bound.
  • Chapter 16 places the lazy finger between static trees searched from the root and dynamic BSTs, with unbounded gaps on both sides.
  • Chapter 17 proves Wilber’s interleave lower bound, which holds for every execution in the rotation, pointer and geometric models. It is the tool behind the O(log⁡log⁡n)O(\log\log n)-competitive Tango trees.
  • Chapter 18 shows that the conditional entropy of the requests is not a benchmark any BST can meet, through Wilber’s bound on a bit-reversal sequence.

A map of the bounds

Two figures collect the relations between them: the first up to constant factors, with the algorithms that meet each bound, and the second with the constants the library proves. Each benchmark is a function of the request sequence XX of length mm on nn keys:

Up to constants

The first figure ignores constant factors and startup terms. An arrow A→BA \to B means that a cost bound O(A)O(A) implies a cost bound O(B)O(B). For most arrows this is an inequality A≤c B+O(n)A \le c\,B + O(n) between the benchmarks themselves; the arrows out of WS\mathrm{WS} and SO\mathrm{SO} are instead implications between properties of algorithms, with the startup allowance D n(1+⌊log⁡2n⌋)D\,n(1 + \lfloor\log_2 n\rfloor) of Chapter 14. “Strict” marks an arrow whose converse fails: the gap is unbounded on some family of sequences. Bounds within constant factors of each other share a box: LF∗=WDF∗\mathrm{LF}^* = \mathrm{WDF}^* (Chapter 15) and RF∗=SO\mathrm{RF}^* = \mathrm{SO} (the entropy bounds of Section 14.3).

The bubbles are algorithms. An arrow from an algorithm to a bound means that the algorithm’s cost is within that ratio of the bound, and so of every bound below it; the ratio is written when it is not constant. Dashed grey arrows are results that are not formalized yet. They are listed in the library’s roadmap, for a later round of proofs.

Algorithm Meets What is proved Lean
Tango trees (Section 26.2) OPT\mathrm{OPT}, ratio O(log⁡log⁡n)O(\log\log n) An online BST algorithm whose total cost is at most (56log⁡2(⌊log⁡2n⌋+1)+16)(56\log_2(\lfloor\log_2 n\rfloor + 1) + 16) times that of any offline execution from the same tree, plus O(nlog⁡log⁡n)O(n \log\log n). exists_competitive
Splay trees (Section 24.2) WS\mathrm{WS} At most 10 WS+6n(1+⌊log⁡2n⌋)10\,\mathrm{WS} + 6n(1 + \lfloor\log_2 n\rfloor) rotations, from every initial tree. Splay.workingSet
Splay trees OPT\mathrm{OPT}, ratio O(log⁡log⁡n⋅log⁡2log⁡log⁡n)O(\log\log n \cdot \log^2\log\log n) Proved by Chmel et al. (2026), a 2026 preprint. not formalized yet
GreedyASS (Section 25.3) LF∗=WDF∗\mathrm{LF}^* = \mathrm{WDF}^* Some online BST algorithm costs at most 722280 LF∗+96303 n722280\,\mathrm{LF}^* + 96303\,n, and at most 2889120 WDF∗+96303 n2889120\,\mathrm{WDF}^* + 96303\,n from every start key. GreedyASS bst
Combined BST (Chapter 31) OPT\mathrm{OPT}, ratio O(log⁡log⁡n)O(\log\log n), and WDF∗=LF∗\mathrm{WDF}^* = \mathrm{LF}^* One causal program, chosen before the requests: GreedyASS and Tango with linear startup, combined by ComboBST and deamortized. Its cost is O(n+min⁡(WDF∗,(m+R)(1+log⁡2(1+⌊log⁡2n⌋))))O(n + \min(\mathrm{WDF}^*, (m + R)(1 + \log_2(1 + \lfloor\log_2 n\rfloor)))) for every offline execution with RR rotations, and each request costs less than 251+195log⁡2n251 + 195\log_2 n. combined
Optimal lazy-finger tree (Chapter 27) LF∗\mathrm{LF}^* A dynamic program builds a static tree whose lazy-finger cost is exactly LF∗\mathrm{LF}^*. It reads the whole sequence first. root_start
Entropy tree (Chapter 19) SO\mathrm{SO}, hence RF∗\mathrm{RF}^* within a factor 3 A static tree with the weighted median at every root costs at most SO\mathrm{SO}. It is built from the access frequencies. entropy_upper_bound
Optimal static tree (Chapter 19) RF∗\mathrm{RF}^* The recurrence builds a static tree of cost exactly RF∗\mathrm{RF}^*, and Knuth’s algorithm computes this cost examining at most 2n22n^2 candidate roots. Both read the whole sequence first. optTree_static, optCost_le_static, knuth_optCost
Balanced static tree (Chapter 19) m(1+log⁡n)m(1 + \log n) The balanced static tree costs at most m(1+log⁡2n)m(1 + \log_2 n) on every sequence. The dynamic trees of Part III have logarithmic height under updates; their search cost against this baseline is not stated as a theorem. balanced_cost_le_logCost
Random trees (Chapter 22) m(1+log⁡n)m(1 + \log n), in expectation In a random BST, every key has expected depth at most 2ln⁡n2 \ln n. Treap updates are not formalized. random_bst_depth_le
Multiple trees (Chapter 28), not a BST m(1+H)m(1+H), ratio O(log⁡n/log⁡c)O(\log n / \log c) With cc successors per key and 10nc10nc words, cost at most 6 m(1+H) (1+log⁡2n)/(1+log⁡2c)6\,m(1+H)\,(1 + \log_2 n)/(1 + \log_2 c), in the linked-search model. MultipleTrees.sequence

With constants

The second figure separates the shared boxes and writes on each arrow the bound that the library proves. Bounds that share a box in the first figure are on one row here, with an arrow each way. The table below lists every arrow with its theorems.

Relation What is proved Lean
IB→OPT\mathrm{IB} \to \mathrm{OPT} Every execution with rr rotations has IB≤4r+2m\mathrm{IB} \le 4r + 2m, for every reference tree. rotation_lower_bound
OPT→LF∗\mathrm{OPT} \to \mathrm{LF}^*, strict From every initial tree, some pointer execution costs at most 464 LF∗+16n464\,\mathrm{LF}^* + 16n. Some families have OPT=o(LF∗)\mathrm{OPT} = o(\mathrm{LF}^*). Dynamic.optimal, Separation.family
OPT→WS\mathrm{OPT} \to \mathrm{WS} From every initial tree, splaying is a pointer execution of cost at most 31 WS+18n(1+⌊log⁡2n⌋)31\,\mathrm{WS} + 18n(1 + \lfloor\log_2 n\rfloor). pointer_workingSet
OPT↛m(1+H)\mathrm{OPT} \not\to m(1+H) No execution bound C m(1+H)+a(n)C\,m(1+H) + a(n) holds, whatever CC and aa. obstruction
LF∗↔WDF∗\mathrm{LF}^* \leftrightarrow \mathrm{WDF}^* LF∗+n≤4(WDF∗+n)\mathrm{LF}^* + n \le 4(\mathrm{WDF}^* + n) and WDF∗+n≤4(LF∗+n)\mathrm{WDF}^* + n \le 4(\mathrm{LF}^* + n). characterization
LF∗→RF∗\mathrm{LF}^* \to \mathrm{RF}^*, strict LF∗≤2 RFt\mathrm{LF}^* \le 2\,\mathrm{RF}_t for every tree tt. Some families have LF∗=o(RF∗)\mathrm{LF}^* = o(\mathrm{RF}^*). optimal_root_finger, Sequential.family
LF∗→DF\mathrm{LF}^* \to \mathrm{DF} LF∗≤n+4 DF\mathrm{LF}^* \le n + 4\,\mathrm{DF}, from any start key. dynamic_finger
SO↔RF∗\mathrm{SO} \leftrightarrow \mathrm{RF}^* SO≤3 RFt\mathrm{SO} \le 3\,\mathrm{RF}_t for every tree tt, and RFt≤SO\mathrm{RF}_t \le \mathrm{SO} for some tt. entropy_lower_bound, entropy_upper_bound
WS→SO\mathrm{WS} \to \mathrm{SO} The working-set property implies static optimality. workingSet_implies_staticOptimality
SO→SF\mathrm{SO} \to \mathrm{SF} Static optimality implies the static finger property, for every finger. staticOptimality_implies_staticFinger
DF→SF\mathrm{DF} \to \mathrm{SF} DF≤2 SFf+log⁡2(∣p−f∣+1)\mathrm{DF} \le 2\,\mathrm{SF}_f + \log_2(\lvert p - f\rvert + 1) for every finger ff and start key pp: a step from xx to yy costs at most the steps from xx to ff and from ff to yy. As properties, dynamic finger implies static finger. dynamicFinger_le_fingerCost, dynamicFinger_implies_staticFinger
SF→m(1+log⁡n)\mathrm{SF} \to m(1 + \log n) SFf≤m(1+log⁡2n)\mathrm{SF}_f \le m(1 + \log_2 n) for every finger f<nf < n. As properties, static finger implies the logarithmic bound, with the same constants. (Only in the first figure.) fingerCost_le_log, staticFinger_implies_logarithmic

Some composite relations are also stated directly, as inequalities between benchmarks: LF∗≤2 SO\mathrm{LF}^* \le 2\,\mathrm{SO} and LF∗≤6 SF\mathrm{LF}^* \le 6\,\mathrm{SF} (Results.static_optimality, Results.static_finger), and a working-set algorithm competes with every fixed tree (Results.workingSet_competes).

Two classical facts are left off both maps. The working-set and dynamic finger bounds are incomparable, each beating the other by an unbounded factor on some family of sequences, but the library has no such families. And the unified charge of Section 14.7 has no formalized relations to the other benchmarks, beyond the splay theorem that uses it.