arXiv:2610.29574cs.DSOct 2026

Manuscript Offprint

arXiv:2610.29574

Dynamically optimal weight-balanced binary search trees

John Iacono, Akash Pareek

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

In STOC 1972, Jürg Nievergelt and Edward M. Reingold introduced the BB[α]BB[\alpha]-tree, also known as a weight-balanced tree, which for any α∈(0,12]\alpha \in (0, \frac{1}{2}] is a binary search tree where every node with induced subtree size ss has children with induced subtree sizes at least α(s+1)−1\alpha(s+1) - 1. A new rotation-based binary search tree, the PopTree, is introduced. The PopTree stores nn elements and is a BB[120]BB[\frac{1}{20}]-tree after the execution of each search and a BB[1729]BB[\frac{1}{729}]-tree at all times, notably while rebalancing. For any constant α\alpha, its performance on search sequences of length Ω(nlog⁡n)\Omega(n \log n) is proved to be within a constant factor (which can depend on α\alpha) of the optimal offline rotation-based binary search tree that maintains the BB[α]BB[\alpha] balance invariant.

1 Introduction

The dynamic optimality conjecture for general rotation-based binary search trees (BST) [ST85] posits that there exists an online rotation-based BST algorithm whose performance is within a constant factor of the optimal offline BST algorithm for every sufficiently long sequence; i.e., there exists a O(1)O(1)-competitive rotation-based BST. This conjecture has received much attention with numerous partial results, for example [Wil89, WDS06, DHIP07, Iac13, Mun00, DHI +^{+}09, Fox11, DILÖ13, CGK +^{+}15b, CGK +^{+}15c, CGK +^{+}15a, CGK +^{+}18, CCS20, LT19, IL16, CGJ +^{+}23, CHH +^{+}26, CGJ +^{+}24]. In addition to the non-constant competitive ratio results [WDS06, DHIP07, LT19, CHH +^{+}26], the failure to obtain dynamic optimality has resulted in the study of adaptive, or beyond-worst-case analysis of general binary search trees to determine which kind of patterns in search sequences can be taken advantage of, and which can not, which has given rise to the study of closed-form bounds including the working set bound [ST85, DILÖ13], the sequential access bound [Fox11, CGK +^{+}15a], the dynamic finger bound and weighted dynamic finger bound [IL16], the unified bound [Iac13, DILÖ13], and bounds for pattern-avoiding sequences [CGK +^{+}15b, CGK +^{+}18, CGJ +^{+}23, CGJ +^{+}24]. This procession of bounds gives some the hope that improving these explicit bounds might lead to a tight bound matching the lower bounds, which so far have been limited to the decades-old bounds of Wilber [Wil89, CCS20] and the perhaps-equivalent independent rectangle bounds [DHI +^{+}09].

However, such rich and intensive study is almost entirely absent from balanced binary search trees, which given their ubiquitousness and the undoubted practical importance of maintaining a logarithmic worst-case running time, is surprising.

This work is meant to be a starting point in answering questions of the form: “Given binary search trees obeying some balance invariant, can you characterize the best rotation-based BSTs that maintain that invariant from the perspective of competitive ratio, dynamic optimality, or beyond worst case bounds?” We emphasize that our view here is to maintain the invariants of balanced BSTs while ignoring the classical update methods, instead allowing any rotation-based

*Université libre de Bruxelles. Research supported by the F.R.S.-FNRS.

†^{\dagger}Ashoka University. Research supported by the F.R.S.-FNRS while the author was at the Université libre de Bruxelles.

implementation of the operations that maintains the balance invariant. In this paper, we look at the class BB[α]BB[\alpha] trees, as balance is their explicit invariant. In doing so we develop a closed-form expression with matching upper and lower bounds which completely characterizes the asymptotic dynamically optimal running time of BB[α]BB[\alpha]-trees. Unsurprisingly, our dynamic optimality characterization shows that there are many classes of sequences for which balanced BSTs are slower than optimal general BSTs, but this is of course useful information telling you when staying in the class of BB[α]BB[\alpha]-trees is sufficient and when for performance reasons you must leave it. What is more surprising is the explicit bound for dynamically optimal BB[α]BB[\alpha]-trees is not one of the extant BST bounds but rather something new.

The BB[α]BB[\alpha]-tree The BB[α]BB[\alpha]-tree is a type of weight-balanced binary search tree (BST) introduced by Jürg Nievergelt and Edward M. Reingold [NR73]. We begin with their definition:

Definition 1. Definition of a BB[α]BB[\alpha]-tree. Let Δ(x)\Delta(x) be the size of the subtree induced at node xx in a BST and define the weight of a node xx, w(x)w(x), to be Δ(x)+1\Delta(x) + 1. Let α\alpha be a constant in the range (0,12](0, \frac{1}{2}] and let β:=1−α\beta := 1 - \alpha. A BB[α]BB[\alpha]-Tree is a binary search tree which for all nodes xx with parent yy:

αw(y)≤w(x)≤βw(y).\alpha w(y)\leq w(x)\leq\beta w(y).

A missing child has a subtree size of zero and is thus treated as having weight one.

The reason for using weight instead of subtree size is that even small examples, such as a two-node BST, would not meet such a definition. However, with weights, a two-node tree is a BB[13]BB[\frac{1}{3}]-tree since the root has weight 3 and the missing child of the root has weight 1. It was shown that no BSTs are BB[α]BB[\alpha]-trees for 13<α≤12\frac{1}{3} < \alpha \leq \frac{1}{2} except perfectly-balanced BSTs which are BB[12]BB[\frac{1}{2}]-trees [NR73]. One nice side effect of weight is that the weight of a node is the sum of the weights of its children. The class of BB[α]BB[\alpha] trees does have its limitations. It is easy to see that a length-m repeated sequential access on a tree with n items takes time Θ(mlog⁡n)\Theta(m \log n) on any BB[α]BB[\alpha] tree, while on splay trees they take O(m)O(m) time [Tar85].

We completely characterize the asymptotic running time of the offline optimal BB[α]BB[\alpha] trees with rotation up to constant factors for sufficiently long sequences of searches. We present a new BST, the PopTree, which is a BB[1729]BB[\frac{1}{729}]-tree whose performance is proved to be within a constant factor of the optimal offline rotation-based BB[α]BB[\alpha]-tree for any constant α∈(0,12]\alpha \in (0, \frac{1}{2}] and a sufficiently long sequence of searches.

The model. Before presenting this characterization, we define precisely what we mean by a rotation-based BB[α]BB[\alpha] algorithm, which we will henceforth call a BB[α]BB[\alpha]-algorithm, following the standard formalization of rotation-based BSTs with the addition of the BB[α]BB[\alpha] balance invariant.

As we do not consider insertions or deletions, we assume that the BST stores the integers from 1 to n. The BB[α]BB[\alpha] algorithm executes a sequence of searches X=⟨x1,x2,…xm⟩X = \langle x_1, x_2, \ldots x_m \rangle, each of which is an item of [n][n]. The BST algorithm has a single pointer, which at unit cost begins each search at the root and at unit cost can move the pointer to the parent, left child, or right child, or it can perform a single rotation involving the node pointed to and the parent of the node pointed to. Any computational time or data stored to determine which unit-cost computations are to be performed are not counted, and an algorithm in the model is free to be offline and make its choices as any function of the entire search sequence. To execute the search for xix_i, the algorithm performs any sequence of unit cost operations provided that (i) the pointer at some point touches the node containing xix_i and (ii) the tree is a valid BB[α]BB[\alpha] at all times during the execution. Each BST algorithm may require an initial starting tree or a class of allowable starting trees.

The optimal running time. Let the set notFirst be all ii such that xix_i is not the first search of that item. Let the previous search at time ii and range rr, prev⁡i(r)\operatorname{prev}_i(r), be defined for any i∈notFirsti \in \text{notFirst} to be

previ(r):=max⁡{j∈[i−1]∣xj∈[xi−r,xi+r]}.\mathrm{p r e v}_{i}(r):=\max\{j\in[i-1]|x_{j}\in[x_{i}-r,x_{i}+r]\}.

Intuitively, this is the time of the most recent search before xix_i with an item within a range ±r\pm r from xix_i. As xix_i was searched before, previ(r)\text{prev}_i(r) is well-defined as it will return the time of the previous search to xix_i if no other item within the range ±r\pm r from xix_i was searched between the time of xix_i's previous search and ii.

We now define our optimal running time for a search sequence X:

OPT(X):=∑i∈notFirst(log⁡min⁡{r≥1∣xprevi(nr)=xi}+log⁡nmin⁡(xi,n−xi+1))(1)OPT(X):=\sum_{i\in not First}\left(\log\min\{r\geq1|x_{prev_{i}(\frac{n}{r})}=x_{i}\}+\log\frac{n}{\min(x_{i},n-x_{i}+1)}\right) \tag{1}

Lower bound. Our main lower bound result shows that any BB[α]BB[\alpha] algorithm, including offline algorithms, has a running time of Ω(OPT(X))\Omega(OPT(X)), where the constant in the Ω\Omega depends on α\alpha. Our upper bound is the presentation of the PopTree data structure, which is an online BB[1729]BB[\frac{1}{729}]-algorithm and whose running time is O(OPT(X))O(OPT(X)) for sequences of length Ω(nlog⁡n)\Omega(n \log n). Together, they show that (1) is the complete asymptotic characterization of the running time of optimal BB[α]BB[\alpha] algorithms, and that our PopTree data structure is O(1)O(1)-competitive with the optimal offline algorithm, otherwise known as being dynamically optimal.

We provide some intuition for (1). One simple observation is that not every item in a BB[α]BB[\alpha] tree can be the root, which implies that the closer an item is to the minimum or maximum, the deeper it must be in the tree. This is formalized in Lemma 3 and is responsible for the second term in (1). For the first term, observe that in a BB[α]BB[\alpha]-tree, given two items with consecutive key values, one of them must be at logarithmic depth. By generalizing this observation to items whose keys are rr apart, one gets that one of them must be at depth Ω(log⁡nr)\Omega(\log \frac{n}{r}) (Lemma 5). So, to execute a search on some item xx in time o(log⁡nr)o(\log \frac{n}{r}) will be problematic if there was some item x′x' with ∣x−x′∣≤r|x - x'| \leq r searched recently. Getting the accounting to work for this case is tricky and requires a charging argument. Such an argument is needed because at the time xx is searched, xx could be shallow and thus cheap to search, and x′x' depth would be Ω(log⁡nr)\Omega(\log \frac{n}{r}), which superficially is not a problem but gives hints of contours of the charging scheme we develop.

Our OPT formula is new and, in some ways, the inverse of the bounds known for general rotation-based BSTs. For such BSTs, the bounds usually capture the concepts of spatial locality (sequential access [Tar85], dynamic finger [CMSS00, Col00]) and temporal locality (working set bound [ST85]) and were combined in the unified bound [Iac01, BCDI07]. The unified bound says that a search is fast if it is close (in key-space) to something that was searched recently. Compare this to our OPT bound, which intuitively says that a search is fast if nothing close (in key-space) was searched recently (since the previous search of the item). It is fascinating that arbitrary BSTs reward locality in key-space while weight-balanced BSTs punish it!

Upper bound. Our PopTree data structure is presented first as a type of skip list [Pug90], where each level has invariants that imply the minimum and maximum number of keys that can be spanned between items. This contrasts with the typical skip list's concern with bounding between two items, and with the number of items one level down. We also have carefully crafted invariants that result in recently searched items being closer to the top of the list if possible, but where the converse does not hold, thus allowing a certain flexibility in restructuring. We promote (pop!) the searched item to the top level of the skip list and then do a series of promotions and demotions.

to restore the invariants of the structure. We convert the skip list to a BST structure via the intermediate step of a B-tree. See Figure 1 for an illustration of a SkipPopTree and the conversion process to a BST via the intermediate step of a B-tree. This conversion process is largely standard, and our invariants are designed to show easily that the resulting BST is a BB[1729]BB[\frac{1}{729}]-tree at all times and a BB[120]BB[\frac{1}{20}]-tree after the completion of any operation. The α=1729\alpha = \frac{1}{729} is only needed during transient states in the middle of an execution, but it serves to show that the BB[α]BB[\alpha] invariant can be maintained at all times, which matches what we require in our lower bound.

Key-independent optimality. In [Iac05], Iacono introduced the notion of key-independent optimality. Given a search sequence X and a random bijection f:[n]↦[n]f: [n] \mapsto [n], let f(X)=⟨f(x1),f(x2),…,f(xm)⟩f(X) = \langle f(x_1), f(x_2), \ldots, f(x_m) \rangle. The intuitive idea is that if we do not expect any correlations in our data based on proximate key values, for example, if key values are some sort of randomly assigned ID, the distributional properties of X and f(X)f(X) should not differ. In [Iac05] it was shown that the expected value of executing f(X)f(X) on the offline optimal BST with rotations was asymptotically the same as what is known as the working set property. As splay trees were shown to have the working set property [ST85], this showed the existence of a BST that, given any sequence f(X)f(X), executes the sequence in time asymptotically the same as the best offline optimal. Such structures were called key-independently optimal. We show in Section 4 that in expectation OPT(f(X))OPT(f(X)) is asymptotically equal to the working-set bound. Thus, we show our PopTree is key-independently optimal and more significantly show that BB[α]BB[\alpha] trees, while much more restricted than general rotation-based BSTs, are all that is needed in the key-independently optimal setting.