Introduction
The dynamic optimality conjecture for general rotation-based binary search trees (BST) [36 ] 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) 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, DILO13, 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 [36 , 20 ] , the sequential access bound [22 CGK+15a] , the dynamic finger bound and weighted dynamic finger bound [27 ] , the unified bound [26 , 20 ] , and bounds for pattern-avoiding sequences [11 , 13 , 9 , 10 ] .
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 [17 ] .
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 implementation of the operations that maintains the balance invariant. In this paper, we look at the class B B [ α ] BB[\alpha] B B [ α ] 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 B B [ α ] BB[\alpha] B B [ α ] -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 B B [ α ] BB[\alpha] B B [ α ] -trees is sufficient and when for performance reasons you must leave it. What is more surprising is the explicit bound for dynamically optimal B B [ α ] BB[\alpha] B B [ α ] -trees is not one of the extant BST bounds but rather something new.
The B B [ α ] BB[\alpha] B B [ α ] -tree. The B B [ α ] BB[\alpha] B B [ α ] -tree is a type of weight-balanced binary search tree (BST) introduced by Jürg Nievergelt and Edward M. Reingold [33 ] . We begin with their definition:
Definition 1. Definition of a B B [ α ] BB[\alpha] B B [ α ] -tree. Let Δ ( x ) \Delta(x) Δ ( x ) be the size of the subtree induced at node x x x in a BST and define the weight of a node x x x , w ( x ) w(x) w ( x ) , to be Δ ( x ) + 1 \Delta(x)+1 Δ ( x ) + 1 . Let α \alpha α be a constant in the range ( 0 , 1 2 ] (0, \frac{1}{2}] ( 0 , 2 1 ] and let β : = 1 − α \beta:= 1-\alpha β := 1 − α . A B B [ α ] BB[\alpha] B B [ α ] -Tree is a binary search tree which for all nodes x x x with parent y y y :
α w ( y ) ≤ w ( x ) ≤ β w ( y ) . \alpha w(y) \le w(x) \le\beta w(y). α w ( y ) ≤ w ( x ) ≤ β 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 B B [ 1 3 ] BB[\frac{1}{3}] B B [ 3 1 ] -tree since the root has weight 3 and the missing child of the root has weight 1. It was shown that no BSTs are B B [ α ] BB[\alpha] B B [ α ] -trees for 1 3 < α ≤ 1 2 \frac{1}{3}<\alpha\le\frac{1}{2} 3 1 < α ≤ 2 1 except perfectly-balanced BSTs which are B B [ 1 2 ] BB[\frac{1}{2}] B B [ 2 1 ] -trees [33 ] . 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 B B [ α ] BB[\alpha] B B [ α ] trees does have its limitations. It is easy to see that a length-m m m repeated sequential access on a tree with n n n items takes time Θ ( m log n ) \Theta(m\log n) Θ ( m log n ) on any B B [ α ] BB[\alpha] B B [ α ] tree, while on splay trees they take O ( m ) O(m) O ( m ) time [37 ] .
We completely characterize the asymptotic running time of the offline optimal B B [ α ] BB[\alpha] B B [ α ] trees with rotation up to constant factors for sufficiently long sequences of searches. We present a new BST, the PopTree, which is a B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -tree whose performance is proved to be within a constant factor of the optimal offline rotation-based B B [ α ] BB[\alpha] B B [ α ] -tree for any constant α ∈ ( 0 , 1 2 ] \alpha\in(0,\frac{1}{2}] α ∈ ( 0 , 2 1 ] and a sufficiently long sequence of searches.
The model. Before presenting this characterization, we define precisely what we mean by a rotation-based B B [ α ] BB[\alpha] B B [ α ] algorithm, which we will henceforth call a B B [ α ] BB[\alpha] B B [ α ] -algorithm, following the standard formalization of rotation-based BSTs with the addition of the B B [ α ] BB[\alpha] B B [ α ] balance invariant.
As we do not consider insertions or deletions, we assume that the BST stores the integers from 1 to n n n . The B B [ α ] BB[\alpha] B B [ α ] algorithm executes a sequence of searches X = ⟨ x 1 , x 2 , … , x m ⟩ X=\langle x_1,x_2,\ldots,x_m\rangle X = ⟨ x 1 , x 2 , … , x m ⟩ , each of which is an item of [ n ] [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 x i x_i x i , the algorithm performs any sequence of unit cost operations provided that (i) the pointer at some point touches the node containing x i x_i x i and (ii) the tree is a valid B B [ α ] BB[\alpha] B B [ α ] 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 i i i such that x i x_i x i is not the first search of that item. Let the previous search at time i i i and range r r r , prev i ( r ) \operatorname{prev}_i(r) prev i ( r ) , be defined for any i ∈ notFirst i \in\text{notFirst} i ∈ notFirst to be
prev i ( r ) : = max { j ∈ [ i − 1 ] ∣ x j ∈ [ x i − r , x i + r ] } . \operatorname{prev}_i(r) := \max\{j \in[i-1] \mid x_j \in[x_i-r,x_i+r]\}. prev i ( r ) := max { j ∈ [ i − 1 ] ∣ x j ∈ [ x i − r , x i + r ]} .
Intuitively, this is the time of the most recent search before x i x_i x i with an item within a range ± r \pm r ± r from x i x_i x i . As x i x_i x i was searched before, prev i ( r ) \operatorname{prev}_i(r) prev i ( r ) is well-defined as it will return the time of the previous search to x i x_i x i if no other item within the range ± r \pm r ± r from x i x_i x i was searched between the time of x i x_i x i ’s previous search and i i i .
We now define our optimal running time for a search sequence X X X :
O P T ( X ) : = ∑ i ∈ notFirst ( log min { r ≥ 1 ∣ x prev i ( r ) = x i } + log n min ( x i , n − x i + 1 ) ) (1) OPT(X) := \sum_{i \in\text{notFirst}} \left(\log\min\{r \ge1 \mid x_{\operatorname{prev}_i(r)} = x_i\} + \log\frac{n}{\min(x_i,n-x_i+1)}\right) \tag*{(1)} O P T ( X ) := i ∈ notFirst ∑ ( log min { r ≥ 1 ∣ x prev i ( r ) = x i } + log min ( x i , n − x i + 1 ) n ) (1)
Lower bound. Our main lower bound result shows that any B B [ α ] BB[\alpha] B B [ α ] algorithm, including offline algorithms, has a running time of Ω ( O P T ( X ) ) \Omega(OPT(X)) Ω ( O P T ( 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 B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -algorithm and whose running time is O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) for sequences of length Ω ( n log n ) \Omega(n \log n) Ω ( n log n ) . Together, they show that (1) is the complete asymptotic characterization of the running time of optimal B B [ α ] BB[\alpha] B B [ α ] algorithms, and that our PopTree data structure is O ( 1 ) 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 B B [ α ] BB[\alpha] B B [ α ] 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 B B [ α ] BB[\alpha] B B [ α ] -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 r r r apart, one gets that one of them must be at depth Ω ( log n r ) \Omega(\log\frac{n}{r}) Ω ( log r n ) (Lemma 5). So, to execute a search on some item x x x in time o ( log n r ) o(\log\frac{n}{r}) o ( log r n ) will be problematic if there was some item x ′ x' x ′ with ∣ x − x ′ ∣ ≤ r |x-x'| \le r ∣ x − x ′ ∣ ≤ 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 x x x is searched, x x x could be shallow and thus cheap to search, and x ′ x' x ′ depth would be Ω ( log n r ) \Omega(\log\frac{n}{r}) Ω ( log r n ) , which superficially is not a problem but gives hints of contours of the charging scheme we develop.
Our O P T OPT O P T 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 [37 ] , dynamic finger [CMS00, Col00]) and temporal locality (working set bound [36 ] ) and were combined in the unified bound [24 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 O P T OPT O P T 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 [34 ] , 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 B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -tree at all times and a B B [ 1 20 ] BB[\frac{1}{20}] B B [ 20 1 ] -tree after the completion of any operation. The α = 1 729 \alpha= \frac{1}{729} α = 729 1 is only needed during transient states in the middle of an execution, but it serves to show that the B B [ α ] BB[\alpha] B B [ α ] invariant can be maintained at all times, which matches what we require in our lower bound.
Figure 1. (a) The SkipPopList on n = 3 4 = 81 n = 3^4 = 81 n = 3 4 = 81 keys. The buckets are defined based on powers of three. Extreme buckets must be empty, occupied buckets cannot be adjacent, and three vacant buckets in a row are prohibited. (b) The PopBTree obtained from (a): each maximal run of consecutive top items of a level forms one node. (c) The PopTree (BST): the right-chain expansion of (b), with each former node shown as a shaded oval. Figure 1: From a SkipPopList to a weight-balanced BST, on one instance. Legend: occupied bucket; vacant bucket; extreme bucket; stored item.
Key-independent optimality. In [25 ] , Iacono introduced the notion of key-independent optimality. Given a search sequence X X X and a random bijection f : [ n ] ↦ [ n ] f : [n] \mapsto[n] f : [ n ] ↦ [ n ] , let f ( X ) = ⟨ f ( x 1 ) , f ( x 2 ) , … , f ( x m ) ⟩ f(X) = \langle f(x_1), f(x_2), \ldots, f(x_m) \rangle f ( X ) = ⟨ f ( x 1 ) , f ( x 2 ) , … , f ( x m )⟩ . 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 X X and f ( X ) f(X) f ( X ) should not differ. In [25 ] it was shown that the expected value of executing f ( X ) 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 [36 ] , this showed the existence of a BST that, given any sequence f ( X ) 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 § 5 that in expectation O P T ( f ( X ) ) OPT(f(X)) O P T ( f ( X )) is asymptotically equal to the working-set bound. Thus, we show our PopTree is key-independently optimal and more significantly show that B B [ α ] BB[\alpha] B B [ α ] trees, while much more restricted than general rotation-based BSTs, are all that is needed in the key-independently optimal setting.
Related work
Weight-balanced trees. The B B [ α ] BB[\alpha] B B [ α ] -tree, or weight-balanced tree, was introduced by Nievergelt and Reingold [33 ] , who proposed maintaining balance by subtree weight rather than by height, achieving logarithmic search and update times using single and double rotations. Most subsequent work on the structure has concerned not new algorithmic capabilities but the correct choice of the balance parameter and of the rebalancing rules. Blum and Mehlhorn [6 ] identified an error in the original analysis, established the admissible parameter range, and proved that the amortized number of rebalancing operations per update is constant. Lai and Wood [30 ] gave a top-down rebalancing procedure. The definitive treatment of the parameter question was given by Hirai and Yamamoto [23 ] , who precisely characterized the valid parameter space and formally verified the rotation conditions in the Coq proof assistant, showing that the rules as originally stated fail for some parameters previously believed valid. Weight-balanced trees found renewed relevance in functional programming through the variant of Adams [1 ] , which underlies the standard persistent set and map libraries of several functional languages. Recently Jugé [28 ] introduced a relaxation in which the weight condition is imposed between nodes and their grandchildren. In all of this work, the object of study is the maintenance of the invariant itself. The question we ask here: the best running time achievable by any sequence of rotations preserving the invariant appears not to have been studied.
Dynamic optimality for binary search trees. Sleator and Tarjan [36 ] introduced splay trees and conjectured that they are O ( 1 ) O(1) O ( 1 ) -competitive with the optimal offline rotation-based BST. This dynamic optimality conjecture remains open, the best known competitive ratio for any BST is the O ( log log n ) O(\log\log n) O ( log log n ) of tango trees [DHI+07]. See [26 ] for a survey. Our result can be read as a resolution of the dynamic optimality question for the class of BST algorithms that maintain the B B [ α ] BB[\alpha] B B [ α ] invariant.
Dynamically optimal skip lists and B-trees. The work closest in spirit to ours is that of Bose, Douïeb, and Langerman [BDL08] on dynamic optimality for skip lists and B-trees. They showed that for skip lists satisfying a weak balancing property, the working-set bound is a lower bound on the cost of executing any search sequence. They constructed a deterministic self-adjusting skip list, which promotes each searched item to the topmost level and then restores the balancing property, whose cost matches the bound. The structure is therefore dynamically optimal within its class, with consequences for ( a , b ) (a,b) ( a , b ) -trees, B-trees, and their BST encodings via standard dualities [21 ] . Their result and ours exhibit the same phenomenon: while dynamic optimality for unrestricted rotation-based BSTs remains open, imposing a balance invariant on the class of structures collapses the offline optimum to an explicit formula that a concrete online structure can match. Indeed, our PopTree takes direct inspiration from their promotion-based structures: it too pops the searched item to the top level of a skip-list representation and repairs its invariants with promotions and demotions. The two characterizations, however, are strikingly different. For balanced skip lists, the optimum is the working-set bound, which is well known from the analysis of splay trees and which rewards temporal locality, recently searched items are cheap. For B B [ α ] BB[\alpha] B B [ α ] -trees, the optimum instead punishes proximity in key space. A search is cheap only if nothing nearby was searched recently, and includes a term forcing items near the minimum or maximum key to be expensive. We further note that in the unrestricted B-tree model, where no balance condition is imposed, only O ( log log n ) O(\log\log n) O ( log log n ) -competitiveness is known [DIKL21], reinforcing that it is the balance restriction that makes full dynamic optimality tractable.
Distribution-sensitive balanced structures. A parallel line of work asks not for the offline optimum but for specific distribution-sensitive bounds achievable while maintaining balance. Bent, Sleator, and Tarjan [7 ] introduced biased search trees, a weight-balanced structure whose access time is O ( 1 + log ( W / w i ) ) O(1+\log(W/w_i)) O ( 1 + log ( W / w i )) for an item of weight w i w_i w i in a tree of total weight W W W . Bagchi, Buchsbaum, and Goodrich [2 ] gave a skip-list counterpart, including a deterministic worst-case variant. Closer to the self-adjusting setting, Bose, Douïeb, Dujmović, and Howat [BDDH12] constructed a height-balanced BST that attains the working-set bound in the worst case and the unified bound amortized, and Martel [31 ] , and Sherk [35 ] studied self-adjusting multiway and k k k -ary trees. In each case, a balance invariant is retained, and a fixed runtime goal (weighted, working-set, or unified) is matched. None characterizes, as we do, the offline optimum over all rotation sequences preserving the invariant.
Organization of the paper. In § 2 we prove the lower bound: every B B [ α ] BB[\alpha] B B [ α ] -algorithm, online or offline, requires time Ω ( O P T ( X ) ) \Omega(OPT(X)) Ω ( O P T ( X )) to execute any search sequence X X X , where the constant depends on α \alpha α . § 3 contains the matching upper bound. We first present the SkipPopList, a skip list with occupancy invariants that tie recently searched items to the top levels, and show that it executes any search sequence of length Ω ( n log n ) \Omega(n\log n) Ω ( n log n ) in time O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) in the skip list cost model. Section A transforms the SkipPopList into weight-balanced multiway search tree, the PopBTree, and Section B transforms the PopBTree into our final structure, the PopTree, a BST maintained by single rotations that is a B B [ 1 2 ] BB[\frac{1}{2}] B B [ 2 1 ] -tree after every search, a B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -tree after every unit-cost operation, and runs in time O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) . § 5 we show that the expectation O P T OPT O P T of a search sequence under a random bijection of the keys equals the working-set bound, establishing that PopTrees are key-independently optimal. We note that the two transformations are placed in the appendix to reflect that these are basically standard transformations, albeit ones where the balance factor needs to be carefully propagated. Our SkipPopList was designed to have these transformations be intuitive. As noted in the acknowledgments, this cleanly separates the paper into the entirely human conceived and written main body of the paper, and the machine written but human edited and verified grind of the two transformations in the appendices which we feel most readers would find believable after looking at Figure 1 .
Lower Bound
This section is about B B [ α ] BB[\alpha] B B [ α ] -trees that store the integers in [ n ] [n] [ n ] and are executing a sequence of m m m searches X = ⟨ x 1 , x 2 , … , x m ⟩ X = \langle x_1, x_2, \ldots, x_m\rangle X = ⟨ x 1 , x 2 , … , x m ⟩ to items in [ n ] [n] [ n ] .
Depth lemmas
We begin by proving some easy lemmas about the depth of items in a B B [ α ] BB[\alpha] B B [ α ] -tree. The depth of a node x x x in a BST, d ( x ) d(x) d ( x ) , is the length of the path from the root to x x x . By repeatedly applying the balance condition in Definition 1 we obtain:
Lemma 2. Weights and depths.
log 1 α n + 1 w ( x ) ≤ d ( x ) ≤ log 1 β n + 1 w ( x ) \log_{\frac{1}{\alpha}} \frac{n+1}{w(x)} \le d(x) \le\log_{\frac{1}{\beta}} \frac{n+1}{w(x)} log α 1 w ( x ) n + 1 ≤ d ( x ) ≤ log β 1 w ( x ) n + 1 The same bounds hold when x x x is a missing child treated as a weight-one node, per Definition 1 .
Lemma 3. Extreme depths. The depth of x x x is at least log 1 α n min ( x , n − x + 1 ) − 1 \log_{\frac{1}{\alpha}} \frac{n}{\min(x,n-x+1)} - 1 log α 1 m i n ( x , n − x + 1 ) n − 1 .
Proof. Node x x x 's left child x L x_L x L (possibly a missing child treated as a weight-one node) has depth d ( x L ) = d ( x ) + 1 d(x_L) = d(x) + 1 d ( x L ) = d ( x ) + 1 and subtree size Δ ( x L ) ≤ x − 1 \Delta(x_L) \le x - 1 Δ ( x L ) ≤ x − 1 and weight w ( x L ) ≤ x w(x_L) \le x w ( x L ) ≤ x . Node x x x 's right child x R x_R x R has depth d ( x R ) = d ( x ) + 1 d(x_R) = d(x) + 1 d ( x R ) = d ( x ) + 1 and subtree size Δ ( x R ) ≤ n − x \Delta(x_R) \le n - x Δ ( x R ) ≤ n − x and thus weight w ( x R ) ≤ n − x + 1 w(x_R) \le n - x + 1 w ( x R ) ≤ n − x + 1 . Apply Lemma 2, using these weights to get the bounds on the depths of x L x_L x L and x R x_R x R (using n + 1 w ≥ n w \frac{n+1}{w} \ge\frac{n}{w} w n + 1 ≥ w n ) and subtract one to get the claimed bound on the depth of x x x .
Lemma 4. Depth ancestor/child. Given any node x x x with ancestor z z z :
d ( x ) ≥ log 1 α n ∣ x − z ∣ − 1. d(x) \ge\log_{\frac{1}{\alpha}} \frac{n}{\lvert x-z\rvert} - 1. d ( x ) ≥ log α 1 ∣ x − z ∣ n − 1. Proof. Assume w.l.o.g. x < z x < z x < z . Let y y y be the right child of x x x (possibly a missing child treated as a weight-one node). We know ∣ Δ ( y ) ∣ ≤ ∣ x − z ∣ − 1 \lvert\Delta(y)\rvert\le\lvert x-z\rvert- 1 ∣ Δ ( y )∣ ≤ ∣ x − z ∣ − 1 and thus w ( y ) ≤ ∣ x − z ∣ w(y) \le\lvert x-z\rvert w ( y ) ≤ ∣ x − z ∣ . We then apply Lemma 2 to y y y and subtract 1 to get the bound on x x x .
Lemma 5. Close nodes imply one is deep. Given any different nodes x x x and z z z :
max ( d ( x ) , d ( z ) ) ≥ log 1 α n ∣ x − z ∣ − 1. \max(d(x),d(z)) \ge\log_{\frac{1}{\alpha}} \frac{n}{\lvert x-z\rvert} - 1. max ( d ( x ) , d ( z )) ≥ log α 1 ∣ x − z ∣ n − 1. Proof. If x x x and z z z have an ancestor/descendant relationship then apply Lemma 4. Otherwise let y y y be the LCA of x x x and z z z . We know that ∣ x − y ∣ + ∣ y − z ∣ = ∣ x − z ∣ \lvert x-y\rvert+ \lvert y-z\rvert= \lvert x-z\rvert ∣ x − y ∣ + ∣ y − z ∣ = ∣ x − z ∣ . We then apply Lemma 4 to y y y and x x x , and y y y and z z z which shows d ( x ) ≥ log 1 α n ∣ x − y ∣ − 1 d(x) \ge\log_{\frac{1}{\alpha}} \frac{n}{\lvert x-y\rvert} - 1 d ( x ) ≥ log α 1 ∣ x − y ∣ n − 1 and d ( z ) ≥ log 1 α n ∣ z − y ∣ − 1 d(z) \ge\log_{\frac{1}{\alpha}} \frac{n}{\lvert z-y\rvert} - 1 d ( z ) ≥ log α 1 ∣ z − y ∣ n − 1 , both of which imply the lemma since ∣ x − y ∣ < ∣ x − z ∣ \lvert x-y\rvert< \lvert x-z\rvert ∣ x − y ∣ < ∣ x − z ∣ and ∣ z − y ∣ < ∣ x − z ∣ \lvert z-y\rvert< \lvert x-z\rvert ∣ z − y ∣ < ∣ x − z ∣ .
Levels
Given a B B [ α ] BB[\alpha] B B [ α ] tree T T T , the level of a node ℓ ( x ) \ell(x) ℓ ( x ) in the tree is defined to be ⌈ log 1 α n + 1 w ( x ) ⌉ \left\lceil\log_{\frac{1}{\alpha}} \frac{n+1}{w(x)} \right\rceil ⌈ log α 1 w ( x ) n + 1 ⌉ . As the root has weight n + 1 n+1 n + 1 , level is a nonnegative integer with the root having level exactly 0. The main feature of levels is that while they largely behave like depths up to constant factors, when performing rotations only the nodes involved can change level while the rest remain the same. This property does not hold for depths.
From the definition of a B B [ α ] BB[\alpha] B B [ α ] tree we now obtain the following:
Lemma 6. Level of a child. Given node x x x with child y y y , either ℓ ( x ) = ℓ ( y ) \ell(x)=\ell(y) ℓ ( x ) = ℓ ( y ) or ℓ ( x ) + 1 = ℓ ( y ) \ell(x)+1=\ell(y) ℓ ( x ) + 1 = ℓ ( y ) .
Proof. By Definition 1, α w ( x ) ≤ w ( y ) ≤ β w ( x ) < w ( x ) \alpha w(x) \le w(y) \le\beta w(x) < w(x) α w ( x ) ≤ w ( y ) ≤ β w ( x ) < w ( x ) . From w ( y ) < w ( x ) w(y)<w(x) w ( y ) < w ( x ) we get log 1 α n + 1 w ( y ) > log 1 α n + 1 w ( x ) \log_{\frac{1}{\alpha}}\frac{n+1}{w(y)} > \log_{\frac{1}{\alpha}}\frac{n+1}{w(x)} log α 1 w ( y ) n + 1 > log α 1 w ( x ) n + 1 , and as the ceiling is nondecreasing, ℓ ( y ) ≥ ℓ ( x ) \ell(y)\ge\ell(x) ℓ ( y ) ≥ ℓ ( x ) . From w ( y ) ≥ α w ( x ) w(y)\ge\alpha w(x) w ( y ) ≥ α w ( x ) we get log 1 α n + 1 w ( y ) ≤ log 1 α n + 1 w ( x ) + 1 \log_{\frac{1}{\alpha}}\frac{n+1}{w(y)} \le\log_{\frac{1}{\alpha}}\frac{n+1}{w(x)}+1 log α 1 w ( y ) n + 1 ≤ log α 1 w ( x ) n + 1 + 1 , and as ⌈ t + 1 ⌉ = ⌈ t ⌉ + 1 \lceil t+1\rceil=\lceil t\rceil+1 ⌈ t + 1 ⌉ = ⌈ t ⌉ + 1 , ℓ ( y ) ≤ ℓ ( x ) + 1 \ell(y)\le\ell(x)+1 ℓ ( y ) ≤ ℓ ( x ) + 1 .
We can also show that depths and levels only differ by a constant.
Lemma 7. Depths and levels. For any node x x x , ℓ ( x ) − 1 ≤ d ( x ) ≤ ℓ ( x ) log α β \ell(x)-1\le d(x)\le\frac{\ell(x)}{\log_{\alpha}\beta} ℓ ( x ) − 1 ≤ d ( x ) ≤ l o g α β ℓ ( x ) .
Proof. In the following, the first step is from Lemma 2, followed by math and the definition of ℓ ( x ) \ell(x) ℓ ( x ) .
d ( x ) ≥ log 1 α n + 1 w ( x ) > ⌈ log 1 α n + 1 w ( x ) ⌉ − 1 = ℓ ( x ) − 1 d(x)\ge\log_{\frac{1}{\alpha}}\frac{n+1}{w(x)}>\left\lceil\log_{\frac{1}{\alpha}}\frac{n+1}{w(x)}\right\rceil-1=\ell(x)-1 d ( x ) ≥ log α 1 w ( x ) n + 1 > ⌈ log α 1 w ( x ) n + 1 ⌉ − 1 = ℓ ( x ) − 1 d ( x ) ≤ log 1 β n + 1 w ( x ) = 1 log 1 α 1 β log 1 α n + 1 w ( x ) ≤ 1 log 1 α 1 β ⌈ log 1 α n + 1 w ( x ) ⌉ = ℓ ( x ) log α β d(x)\le\log_{\frac{1}{\beta}}\frac{n+1}{w(x)}=\frac{1}{\log_{\frac{1}{\alpha}}\frac{1}{\beta}}\log_{\frac{1}{\alpha}}\frac{n+1}{w(x)}\le\frac{1}{\log_{\frac{1}{\alpha}}\frac{1}{\beta}}\left\lceil\log_{\frac{1}{\alpha}}\frac{n+1}{w(x)}\right\rceil=\frac{\ell(x)}{\log_{\alpha}\beta} d ( x ) ≤ log β 1 w ( x ) n + 1 = log α 1 β 1 1 log α 1 w ( x ) n + 1 ≤ log α 1 β 1 1 ⌈ log α 1 w ( x ) n + 1 ⌉ = log α β ℓ ( x )
We thus take the depth result of Lemma 5 and use the ℓ ( x ) ≥ log α β ⋅ d ( x ) \ell(x)\ge\log_{\alpha}\beta\cdot d(x) ℓ ( x ) ≥ log α β ⋅ d ( x ) of Lemma 7 to give a level-based result.
Lemma 8. Close nodes imply high level. Given any different nodes x x x and z z z , one has level at least log α β log 1 α n ∣ x − z ∣ − 1 \log_{\alpha}\beta\log_{\frac{1}{\alpha}}\frac{n}{|x-z|}-1 log α β log α 1 ∣ x − z ∣ n − 1 .
Proof.
max ( ℓ ( x ) , ℓ ( z ) ) ≥ max ( log α β ⋅ d ( x ) , log α β ⋅ d ( z ) ) Lemma 7 = log α β max ( d ( x ) , d ( z ) ) ≥ log α β ( log 1 α n ∣ x − z ∣ − 1 ) Lemma 5 ≥ log α β log 1 α n ∣ x − z ∣ − 1 0 < log α β ≤ 1 \begin{aligned}
\max(\ell(x),\ell(z))&\ge\max(\log_{\alpha}\beta\cdot d(x),\log_{\alpha}\beta\cdot d(z)) && \text{Lemma 7}\\
&=\log_{\alpha}\beta\max(d(x),d(z))\\
&\ge\log_{\alpha}\beta\left(\log_{\frac{1}{\alpha}}\frac{n}{|x-z|}-1\right) && \text{Lemma 5}\\
&\ge\log_{\alpha}\beta\log_{\frac{1}{\alpha}}\frac{n}{|x-z|}-1 && 0<\log_{\alpha}\beta\le1
\end{aligned} max ( ℓ ( x ) , ℓ ( z )) ≥ max ( log α β ⋅ d ( x ) , log α β ⋅ d ( z )) = log α β max ( d ( x ) , d ( z )) ≥ log α β ( log α 1 ∣ x − z ∣ n − 1 ) ≥ log α β log α 1 ∣ x − z ∣ n − 1 Lemma 7 Lemma 5 0 < log α β ≤ 1
Lemma 9. γ ( ℓ ) \gamma(\ell) γ ( ℓ ) : the threshold of closeness to be at level ℓ \ell ℓ . Let γ ( ℓ ) : = n α ℓ + 1 log α β \gamma(\ell):=n\alpha^{\frac{\ell+1}{\log_{\alpha}\beta}} γ ( ℓ ) := n α l o g α β ℓ + 1 . Given any two nodes x x x and z z z , if ∣ x − z ∣ ≤ γ ( ℓ ) |x-z|\le\gamma(\ell) ∣ x − z ∣ ≤ γ ( ℓ ) , the level of at least one of x x x and z z z is at least ℓ \ell ℓ .
Proof. The inequality max ( ℓ ( x ) , ℓ ( z ) ) ≥ log α β log 1 α n ∣ x − z ∣ − 1 \max(\ell(x),\ell(z))\ge\log_{\alpha}\beta\log_{\frac{1}{\alpha}}\frac{n}{|x-z|}-1 max ( ℓ ( x ) , ℓ ( z )) ≥ log α β log α 1 ∣ x − z ∣ n − 1 from Lemma 8 and ∣ x − z ∣ ≥ γ ( max ( ℓ ( x ) , ℓ ( z ) ) ) |x-z|\ge\gamma(\max(\ell(x),\ell(z))) ∣ x − z ∣ ≥ γ ( max ( ℓ ( x ) , ℓ ( z ))) are equivalent via algebra. Thus we have
γ ( ℓ ) ≥ ∣ x − z ∣ ≥ γ ( max ( ℓ ( x ) , ℓ ( z ) ) ) . \gamma(\ell)\ge|x-z|\ge\gamma(\max(\ell(x),\ell(z))). γ ( ℓ ) ≥ ∣ x − z ∣ ≥ γ ( max ( ℓ ( x ) , ℓ ( z ))) . This implies that ℓ ≤ max ( ℓ ( x ) , ℓ ( z ) ) \ell\le\max(\ell(x),\ell(z)) ℓ ≤ max ( ℓ ( x ) , ℓ ( z )) since γ \gamma γ is decreasing in ℓ \ell ℓ .
Algorithm
In this section, we assume an algorithm A \mathcal{A} A which executes the search sequence X = ⟨ x 1 , x 2 , … x m ⟩ X = \langle x_1, x_2, \ldots x_m \rangle X = ⟨ x 1 , x 2 , … x m ⟩ where each search is an item in [ n ] [n] [ n ] . Let T i T_i T i denote the tree before the execution of x i x_i x i .
An algorithm begins each search by initializing the pointer to be the root at unit cost and does a series of unit cost operations by moving the pointer left, right, up, or doing a single rotation with the parent with the single rule that at some point in the execution of the i i i th search, x i x_i x i , the pointer must touch x i x_i x i . Additionally, to be a valid B B [ α ] BB[\alpha] B B [ α ] -algorithm, the tree must be a valid B B [ α ] BB[\alpha] B B [ α ] -tree at all times.
Let A ( A , T 0 , X ) A(\mathcal{A}, T_0, X) A ( A , T 0 , X ) be the cost of the algorithm to execute X X X starting from the initial tree T 0 T_0 T 0 , in terms of the unit cost operations previously presented.
All other notation from this point on in this section may implicitly depend on A \mathcal{A} A , X X X , and T 0 T_0 T 0 . Other notation previously defined with reference to a BST may now be subscripted to refer to T i T_i T i , e.g. ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) is the level of the i i i th item to be searched just before the algorithm commences. For brevity, we refer to the node p p p points to, as well as the nodes themselves, by the value of the data in the node. As each node stores a unique value in [ n ] [n] [ n ] , this is unambiguous.
We now introduce notation to give a unique identifier to each unit-cost operation. Note that it is not sufficient to simply identify the items the pointer points to during the course of executing a search, as a pointer could point to an item several times.
We define the set A \mathcal{A} A to be all 4-tuples ( i , j , p , ℓ ) (i,j,p,\ell) ( i , j , p , ℓ ) where p p p is the value stored in the node pointed to by the pointer after the ( j + 1 ) (j+1) ( j + 1 ) st unit-cost operation during the execution of the i i i th search and ℓ \ell ℓ is the level of p p p in the tree at that moment. Note that i i i is in the range [ 1.. m ] [1..m] [ 1.. m ] as there are m m m searches, and j j j is in the range from 0 to one less than the number of unit-cost operations used to execute the i i i th search. The value j = 0 j=0 j = 0 will represent the state after the first unit-cost operation of the i i i th search, the initialization of the pointer to the root of the tree. Thus, A \mathcal{A} A provides a full transcript of the execution of the algorithm, and also encodes the level of the pointer at every step.
Lemma 10. Relating the size of A \mathcal{A} A and the running time of the algorithm. ∣ A ∣ = A ( A , T 0 , X ) |\mathcal{A}| = A(\mathcal{A},T_0,X) ∣ A ∣ = A ( A , T 0 , X ) .
Proof. The elements of A \mathcal{A} A are in bijection with the unit-cost operations performed by the algorithm: ( i , j , p , ℓ ) (i,j,p,\ell) ( i , j , p , ℓ ) corresponds to the ( j + 1 ) (j+1) ( j + 1 ) st unit-cost operation of the i i i th search.
Levels and algorithm
Lemma 11. Only rotations change levels. In a rotation, only the levels of the two nodes involved can change. Thus, the level of a node can not change during the execution of a search before the first time the pointer touches the item.
Proof. The level is a function of weight, which changes only at the two nodes involved in a rotation. For the second claim, we show that at all times during a search, every ancestor of the pointed node has been touched during that search. The claim follows as the two nodes involved in a rotation are the pointed node x x x (touched by definition) and its parent y y y (an ancestor). The invariant holds by induction on the unit-cost operations, it holds after the initialization of the pointer to the root, which has no ancestors. Moving the pointer to a child adds only the previously pointed node to the set of ancestors of the pointed node. Moving the pointer to the parent removes it from the set, and a rotation of the pointed node x x x with its parent y y y removes y y y from the set.
Lemma 12. The pointer touches nodes at all levels smaller than the level of what it is searching. Given any 0 ≤ ℓ ≤ ℓ i ( x i ) 0 \leq\ell\leq\ell_i(x_i) 0 ≤ ℓ ≤ ℓ i ( x i ) , there must be a p p p and j j j such that there is a ( i , j , p , ℓ ) ∈ A (i,j,p,\ell) \in\mathcal{A} ( i , j , p , ℓ ) ∈ A .
Proof. Lemma 6, showing a child is at the same level or + 1 +1 + 1 compared to the parent almost is the proof but a bit more detail is needed to make sure that as the pointer performs rotations that this can not be used to skip a level. The tuple ( i , 0 , root , 0 ) (i,0,\operatorname{root},0) ( i , 0 , root , 0 ) covers the case ℓ ′ = 0 \ell'=0 ℓ ′ = 0 . Each unit-cost operation changes the level of the pointed node by at most one: moving to a child changes it by 0 0 0 or + 1 +1 + 1 (Lemma 6), moving to the parent by 0 0 0 or − 1 -1 − 1 , and in a rotation the pointed node takes the position, and thus the weight and level, previously held by its parent, a change of 0 0 0 or − 1 -1 − 1 (Lemma 6). By Lemma 11, the first time the pointer touches x i x_i x i during search i i i , its level is still ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) . The sequence of levels in the tuples ( i , 0 , ⋅ , ⋅ ) , ( i , 1 , ⋅ , ⋅ ) , … (i,0,\cdot,\cdot),(i,1,\cdot,\cdot),\ldots ( i , 0 , ⋅ , ⋅ ) , ( i , 1 , ⋅ , ⋅ ) , … therefore starts at 0 0 0 , at some point reaches ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) , and changes by at most one per step, and so takes every value ℓ ′ ∈ [ 0 , ℓ i ( x i ) ] \ell' \in[0,\ell_i(x_i)] ℓ ′ ∈ [ 0 , ℓ i ( x i )] .
Lemma 13. Downward continuity of the level of an item. Given, times i i i and i ′ ′ i'' i ′′ where i < i ′ ′ i < i'' i < i ′′ , item y y y , and level ℓ \ell ℓ with ℓ i ′ ′ ( y ) < ℓ ≤ ℓ i ( y ) \ell_{i''}(y) < \ell\le\ell_i(y) ℓ i ′′ ( y ) < ℓ ≤ ℓ i ( y ) . There is a time i ′ ∈ [ i , i ′ ′ ) i' \in[i,i'') i ′ ∈ [ i , i ′′ ) and a j j j such that ( i ′ , j , y , ℓ ) ∈ A (i',j,y,\ell) \in A ( i ′ , j , y , ℓ ) ∈ A .
Proof. By Lemma 11, the level of y y y changes only in rotations involving y y y , and any such change is by exactly one: consider a rotation of a node x x x with parent y ′ y' y ′ , and set ℓ ′ = ℓ ( y ′ ) \ell'=\ell(y') ℓ ′ = ℓ ( y ′ ) before the rotation. Before the rotation, ℓ ( x ) \ell(x) ℓ ( x ) was ℓ ′ \ell' ℓ ′ or ℓ ′ + 1 \ell'+1 ℓ ′ + 1 and after it will be ℓ ′ \ell' ℓ ′ . Before the rotation ℓ ( y ′ ) \ell(y') ℓ ( y ′ ) is ℓ ′ \ell' ℓ ′ and after it will be ℓ ′ \ell' ℓ ′ or ℓ ′ + 1 \ell'+1 ℓ ′ + 1 (Lemma 6). Thus, when y y y is the parent in a rotation, its level stays the same or increases by one. Its level decreases only when y y y is the pointed node and is rotated up with its parent, and in that case, the pointer is at y y y immediately before the rotation, so a tuple ( ⋅ , ⋅ , y , ℓ ( y ) ) (\cdot,\cdot,y,\ell(y)) ( ⋅ , ⋅ , y , ℓ ( y )) with y y y 's pre-rotation level is in A A A . The level of y y y is at least ℓ \ell ℓ at time i i i and less than ℓ \ell ℓ at time i ′ ′ i'' i ′′ and moves in unit steps, so during some search i ′ ∈ [ i , i ′ ′ ) i' \in[i,i'') i ′ ∈ [ i , i ′′ ) it decreases from ℓ \ell ℓ to ℓ − 1 \ell-1 ℓ − 1 . Thus, the touch of y y y at level ℓ \ell ℓ immediately before that rotation is the required tuple.
Previous search
Recall that n o t F i r s t \mathrm{notFirst} notFirst is the subset of [ m ] [m] [ m ] consisting of i i i where x i x_i x i is not the first search of x i x_i x i in X X X . As we will often be looking at the previous search of an item, it will be helpful to exclude items being searched for the first time from our analysis. Observe ∣ n o t F i r s t ∣ ≥ m − n |\mathrm{notFirst}| \ge m-n ∣ notFirst ∣ ≥ m − n as each item in [ n ] [n] [ n ] can only be searched for the first time once.
Given an i ∈ n o t F i r s t i \in\mathrm{notFirst} i ∈ notFirst , define p r e v i \mathrm{prev}_i prev i to be the time of the previous search to x i x_i x i before time i i i :
p r e v i : = max { i ′ ∣ i ′ < i and x i ′ = x i } . \mathrm{prev}_i := \max\{i' \mid i' < i \text{ and } x_{i'}=x_i\}. prev i := max { i ′ ∣ i ′ < i and x i ′ = x i } .
Given an i ∈ n o t F i r s t i \in\mathrm{notFirst} i ∈ notFirst , define p r e v i ( r ) \mathrm{prev}_i(r) prev i ( r ) to be the j j j such that x j x_j x j is the most recently searched item in [ x i − r , x i + r ] [x_i-r,x_i+r] [ x i − r , x i + r ] before time i i i :
p r e v i ( r ) : = max { i ′ ∣ i ′ < i and x i ′ ∈ [ x i − r , x i + r ] } . \mathrm{prev}_i(r) := \max\{i' \mid i' < i \text{ and } x_{i'} \in[x_i-r,x_i+r]\}. prev i ( r ) := max { i ′ ∣ i ′ < i and x i ′ ∈ [ x i − r , x i + r ]} .
This is well-defined as x i x_i x i has been searched before and this previous search ensures that the set will have at least one element, p r e v i \mathrm{prev}_i prev i . This observation also gives the following lemma:
Lemma 14. For any i ∈ n o t F i r s t i \in\mathrm{notFirst} i ∈ notFirst , and any r ≥ 0 r \ge0 r ≥ 0 , p r e v i ≤ p r e v i ( r ) \mathrm{prev}_i \le\mathrm{prev}_i(r) prev i ≤ prev i ( r ) )
Proof. Observe that for fixed i i i , p r e v i ( r ) \mathrm{prev}_i(r) prev i ( r ) is nondecreasing as a function of r r r . Furthermore for r = 0 r=0 r = 0 , p r e v i ( r ) = p r e v i \mathrm{prev}_i(r)=\mathrm{prev}_i prev i ( r ) = prev i .
Marking scheme
For every i ∈ n o t F i r s t i \in\mathrm{notFirst} i ∈ notFirst and every nonnegative integer ℓ \ell ℓ where x i ≠ x p r e v i ( γ ( ℓ ) ) x_i \ne x_{\mathrm{prev}_i(\gamma(\ell))} x i = x prev i ( γ ( ℓ )) we define the following marking scheme which maps ( i , ℓ ) (i,\ell) ( i , ℓ ) to a touch ( i ′ , j , p , ℓ ) (i',j,p,\ell) ( i ′ , j , p , ℓ ) in $A. Type 1 mark. If ℓ i ( x i ) ≥ ℓ \ell_i(x_i) \ge\ell ℓ i ( x i ) ≥ ℓ then by Lemma 12 there is j j j and p p p so that ( i , j , p , ℓ ) ∈ A (i,j,p,\ell) \in A ( i , j , p , ℓ ) ∈ A . We mark this touch with a type-1 mark. We use the minimum j j j if there are multiple possibilities. Intuitively, when searching for something deeper than level ℓ \ell ℓ , one must touch a node at level ℓ \ell ℓ on the way.
Type 2 marks. In this case we assume a type 1 mark is not possible (ℓ i ( x i ) < ℓ \ell_i(x_i) < \ell ℓ i ( x i ) < ℓ ) and ℓ prev i ( γ ( ℓ ) ) ( x prev i ( γ ( ℓ ) ) ) ≥ ℓ \ell_{\operatorname{prev}_i(\gamma(\ell))}(x_{\operatorname{prev}_i(\gamma(\ell))}) \ge\ell ℓ prev i ( γ ( ℓ )) ( x prev i ( γ ( ℓ )) ) ≥ ℓ . By Lemma 12 there is j j j and p p p so that ( prev i ( γ ( ℓ ) ) , j , p , ℓ ) ∈ A (\operatorname{prev}_i(\gamma(\ell)),j,p,\ell) \in A ( prev i ( γ ( ℓ )) , j , p , ℓ ) ∈ A . We use the minimum j j j if there are multiple possibilities. Intuitively, this is the same logic as the type 1 mark, except in this case the deep search is not x i x_i x i but rather x prev i ( γ ( ℓ ) ) x_{\operatorname{prev}_i(\gamma(\ell))} x prev i ( γ ( ℓ )) .
Type 3 mark. If type 1 and type 2 marks are not possible, we have ℓ i ( x i ) < ℓ \ell_i(x_i) < \ell ℓ i ( x i ) < ℓ and ℓ prev i ( γ ( ℓ ) ) ( x prev i ( γ ( ℓ ) ) ) < ℓ \ell_{\operatorname{prev}_i(\gamma(\ell))}(x_{\operatorname{prev}_i(\gamma(\ell))}) < \ell ℓ prev i ( γ ( ℓ )) ( x prev i ( γ ( ℓ )) ) < ℓ . Observe that ∣ x i − x prev i ( γ ( ℓ ) ) ∣ ≤ γ ( ℓ ) |x_i-x_{\operatorname{prev}_i(\gamma(\ell))}| \le\gamma(\ell) ∣ x i − x prev i ( γ ( ℓ )) ∣ ≤ γ ( ℓ ) by the definition of prev. We now apply Lemma 9 to the tree T prev i ( γ ( ℓ ) ) T_{\operatorname{prev}_i(\gamma(\ell))} T prev i ( γ ( ℓ )) and at least one of x i x_i x i and x prev i ( γ ( ℓ ) ) x_{\operatorname{prev}_i(\gamma(\ell))} x prev i ( γ ( ℓ )) must be at level at least ℓ \ell ℓ in this tree. Since ℓ prev i ( γ ( ℓ ) ) ( x prev i ( γ ( ℓ ) ) ) < ℓ \ell_{\operatorname{prev}_i(\gamma(\ell))}(x_{\operatorname{prev}_i(\gamma(\ell))}) < \ell ℓ prev i ( γ ( ℓ )) ( x prev i ( γ ( ℓ )) ) < ℓ we conclude that it must be x i x_i x i as ℓ prev i ( γ ( ℓ ) ) ( x i ) ≥ ℓ \ell_{\operatorname{prev}_i(\gamma(\ell))}(x_i) \ge\ell ℓ prev i ( γ ( ℓ )) ( x i ) ≥ ℓ . Now we have at time i i i the level of x i x_i x i was less than ℓ \ell ℓ and at time prev i ( γ ( ℓ ) ) \operatorname{prev}_i(\gamma(\ell)) prev i ( γ ( ℓ )) the level of x i x_i x i was at least ℓ \ell ℓ , i.e., ℓ prev i ( γ ( ℓ ) ) ( x i ) ≥ ℓ \ell_{\operatorname{prev}_i(\gamma(\ell))}(x_i) \ge\ell ℓ prev i ( γ ( ℓ )) ( x i ) ≥ ℓ and ℓ i ( x i ) < ℓ \ell_i(x_i) < \ell ℓ i ( x i ) < ℓ . Thus by the downward continuity of levels, Lemma 13 applied with times prev i ( γ ( ℓ ) ) \operatorname{prev}_i(\gamma(\ell)) prev i ( γ ( ℓ )) and i i i , x i x_i x i must have been touched at level ℓ \ell ℓ during the execution of some search i ′ i' i ′ with prev i ( γ ( ℓ ) ) ≤ i ′ < i \operatorname{prev}_i(\gamma(\ell)) \le i' < i prev i ( γ ( ℓ )) ≤ i ′ < i . It is the first such touch ( i ′ , j , x i , ℓ ) ∈ A (i',j,x_i,\ell) \in A ( i ′ , j , x i , ℓ ) ∈ A that we mark with a type 3 mark.
Lemma 15. No touch in A A A receives more than four marks.
Proof. Specifically, we show that no touch in A A A receives more than one Type-1 mark, two Type-2 marks and one Type-3 mark.
Type 1: Given i i i and ℓ \ell ℓ , this marks ( i , j , p , ℓ ) (i,j,p,\ell) ( i , j , p , ℓ ) for some p p p and j j j and thus a different choice of i i i and/or ℓ \ell ℓ will type-1 mark a different element of A A A .
Type 2 marks: We show that no touch receives more than two type-2 marks. A type-2 mark generated by the pair ( i , ℓ ) (i,\ell) ( i , ℓ ) marks a touch of the form ( prev i ( γ ( ℓ ) ) , j , p , ℓ ) (\operatorname{prev}_i(\gamma(\ell)),j,p,\ell) ( prev i ( γ ( ℓ )) , j , p , ℓ ) . In particular the fourth coordinate of the marked touch is ℓ \ell ℓ . Thus pairs with different values of ℓ \ell ℓ mark different touches, and we fix ℓ \ell ℓ for the remainder of the argument. For brevity, let r : = γ ( ℓ ) r := \gamma(\ell) r := γ ( ℓ ) , and for a pair ( i , ℓ ) (i,\ell) ( i , ℓ ) generating a type-2 mark, let q i : = prev i ( r ) q_i := \operatorname{prev}_i(r) q i := prev i ( r ) be the time of the marked touch. Two pairs ( i , ℓ ) (i,\ell) ( i , ℓ ) and ( i ^ , ℓ ) (\hat{i},\ell) ( i ^ , ℓ ) can mark the same touch only if q i = q i ^ q_i=q_{\hat{i}} q i = q i ^ . Therefore, it suffices to show that at most two indices i i i generating type-2 marks share the same value of q i q_i q i .
Suppose ( i , ℓ ) (i,\ell) ( i , ℓ ) and ( i ^ , ℓ ) (\hat{i},\ell) ( i ^ , ℓ ) both generate type-2 marks, with i ≠ i ^ i \ne\hat{i} i = i ^ and q i = q i ^ = : q q_i=q_{\hat{i}}=:q q i = q i ^ =: q , without loss of generality assume i < i ^ i<\hat{i} i < i ^ . By the definition of prev, q < i < i ^ q<i<\hat{i} q < i < i ^ . We establish three facts.
Fact 1: ∣ x i − x q ∣ ≤ r |x_i-x_q| \le r ∣ x i − x q ∣ ≤ r and ∣ x i ^ − x q ∣ ≤ r |x_{\hat{i}}-x_q| \le r ∣ x i ^ − x q ∣ ≤ r . This is immediate from the definition of prev i ( r ) \operatorname{prev}_i(r) prev i ( r ) and prev i ^ ( r ) \operatorname{prev}_{\hat{i}}(r) prev i ^ ( r ) : the item searched at time q q q has key in [ x i − r , x i + r ] [x_i-r,x_i+r] [ x i − r , x i + r ] and in [ x i ^ − r , x i ^ + r ] [x_{\hat{i}}-r,x_{\hat{i}}+r] [ x i ^ − r , x i ^ + r ] .
Fact 2: x i ≠ x q x_i \ne x_q x i = x q and x i ^ ≠ x q x_{\hat{i}} \ne x_q x i ^ = x q . The marking scheme is only defined for pairs ( i , ℓ ) (i,\ell) ( i , ℓ ) with x i ≠ x prev i ( γ ( ℓ ) ) x_i \ne x_{\operatorname{prev}_i(\gamma(\ell))} x i = x prev i ( γ ( ℓ )) .
Fact 3: ∣ x i − x i ^ ∣ > r |x_i-x_{\hat{i}}| > r ∣ x i − x i ^ ∣ > r . Suppose not, so x i ∈ [ x i ^ − r , x i ^ + r ] x_i \in[x_{\hat{i}}-r,x_{\hat{i}}+r] x i ∈ [ x i ^ − r , x i ^ + r ] . Since q < i < i ^ q<i<\hat{i} q < i < i ^ , time i i i is then a candidate in the maximum defining prev i ^ ( r ) \operatorname{prev}_{\hat{i}}(r) prev i ^ ( r ) , giving q = prev i ^ ( r ) ≥ i q=\operatorname{prev}_{\hat{i}}(r) \ge i q = prev i ^ ( r ) ≥ i . This contradicts q < i q<i q < i .
By Fact 2, neither x i x_i x i nor x i ^ x_{\hat{i}} x i ^ equals x q x_q x q , leaving two cases for their positions relative to x q x_q x q .
Case 1: x i x_i x i and x i ^ x_{\hat{i}} x i ^ lie on the same side of x q x_q x q . Assume both are smaller than x q x_q x q , the case where both are larger is symmetric. By Fact 1 both lie in [ x q − r , x q ) [x_q-r,x_q) [ x q − r , x q ) , an interval of length r r r , so ∣ x i − x i ^ ∣ < r |x_i-x_{\hat{i}}| < r ∣ x i − x i ^ ∣ < r , contradicting Fact 3. This case is impossible.
Case 2: x i x_i x i and x i ^ x_{\hat{i}} x i ^ lie on opposite sides of x q x_q x q . This is the only remaining possibility. Therefore, among all pairs ( i , ℓ ) (i,\ell) ( i , ℓ ) generating type-2 marks with q i = q q_i=q q i = q , at most one has x i < x q x_i < x_q x i < x q and at most one has x i > x q x_i > x_q x i > x q , since two on the same side would realize the impossible Case 1. Thus at most two pairs mark touches at time q q q with level ℓ \ell ℓ , and no touch receives more than two type-2 marks.
Type 3 marks: Given i i i and ℓ \ell ℓ , this always marks ( i ′ , j , x i , ℓ ) (i',j,x_i,\ell) ( i ′ , j , x i , ℓ ) for some i ′ i' i ′ in the range [ prev i ( γ ( ℓ ) ) , i ) [\operatorname{prev}_i(\gamma(\ell)),i) [ prev i ( γ ( ℓ )) , i ) . By Lemma 14 [ prev i ( γ ( ℓ ) ) , i ) ⊆ [ prev i , i ) [\operatorname{prev}_i(\gamma(\ell)),i) \subseteq[\operatorname{prev}_i,i) [ prev i ( γ ( ℓ )) , i ) ⊆ [ prev i , i ) . Observe that if x i = x i ^ x_i = x_{\hat{i}} x i = x i ^ , i ≠ i ^ i \ne\hat{i} i = i ^ that the intervals [ prev i , i ) [\operatorname{prev}_i,i) [ prev i , i ) and [ prev i ^ , i ^ ) [\operatorname{prev}_{\hat{i}},\hat{i}) [ prev i ^ , i ^ ) are disjoint. Thus no other search x i ^ x_{\hat{i}} x i ^ and ℓ \ell ℓ could mark ( i ′ , j , x i , ℓ ) (i',j,x_i,\ell) ( i ′ , j , x i , ℓ ) as the touch it would mark would not have an i ′ i' i ′ -value in [ prev i , i ) [\operatorname{prev}_i,i) [ prev i , i ) .
Lemma 16. The time to execute X X X on a B B [ α ] BB[\alpha] B B [ α ] -tree is at least
1 4 ∣ { ( i , ℓ ) ∣ i ∈ n o t F i r s t and x prev i ( γ ( ℓ ) ) ≠ x i } ∣ \frac{1}{4}\left|\left\{(i,\ell)\mid i\in\mathrm{notFirst}\text{ and }x_{\operatorname{prev}_i}(\gamma(\ell))\ne x_i\right\}\right| 4 1 { ( i , ℓ ) ∣ i ∈ notFirst and x prev i ( γ ( ℓ )) = x i } Proof. Each element of { ( i , ℓ ) ∣ i ∈ n o t F i r s t and x prev i ( γ ( ℓ ) ) ≠ x i } \{(i,\ell)\mid i\in\mathrm{notFirst}\text{ and }x_{\operatorname{prev}_i}(\gamma(\ell))\ne x_i\} {( i , ℓ ) ∣ i ∈ notFirst and x prev i ( γ ( ℓ )) = x i } marks an element of A A A . By Lemma 15, each element of A A A receives at most 4 marks, so at least
1 4 ∣ { ( i , ℓ ) ∣ i ∈ n o t F i r s t and x prev i ( γ ( ℓ ) ) ≠ x i } ∣ \frac{1}{4}\left|\left\{(i,\ell)\mid i\in\mathrm{notFirst}\text{ and }x_{\operatorname{prev}_i}(\gamma(\ell))\ne x_i\right\}\right| 4 1 { ( i , ℓ ) ∣ i ∈ notFirst and x prev i ( γ ( ℓ )) = x i } distinct elements of A A A receive marks, giving a lower bound on the size of A A A . Finally by Lemma 10 ∣ A ∣ = A ( A , T 0 , X ) |A|=A(A,T_0,X) ∣ A ∣ = A ( A , T 0 , X ) , so a lower bound on ∣ A ∣ |A| ∣ A ∣ is a lower bound on the execution time of the algorithm.
Theorem 17. The time to execute X X X on a B B [ α ] BB[\alpha] B B [ α ] -tree with constant α \alpha α is Ω ( OPT ( X ) ) \Omega(\operatorname{OPT}(X)) Ω ( OPT ( X )) :
Ω ( ∑ i ∈ n o t F i r s t ( log min { r ≥ 1 ∣ x prev i ( r n ) = x i } + log n min ( x i , n − x i + 1 ) ) ) . \Omega\left(\sum_{i\in\mathrm{notFirst}}\left(\log\min\left\{r\ge1\mid x_{\operatorname{prev}_i}\left(\frac{r}{n}\right)=x_i\right\}+\log\frac{n}{\min(x_i,n-x_i+1)}\right)\right). Ω ( i ∈ notFirst ∑ ( log min { r ≥ 1 ∣ x prev i ( n r ) = x i } + log min ( x i , n − x i + 1 ) n ) ) . Proof. The second term: From Lemma 3, the depth of x i x_i x i in the tree T i T_i T i is at least log 1 α n min ( x i , n − x i + 1 ) − 1 \log\frac{1}{\alpha}\frac{n}{\min(x_i,n-x_i+1)}-1 log α 1 m i n ( x i , n − x i + 1 ) n − 1 . Each unit-cost operation changes the distance in the current tree between the pointed node and x i x_i x i by at most one. This is immediate for the pointer movements, and in a rotation of the pointed node x x x with its parent y y y , the distance from x x x increases by one for nodes in the subtree of the child of x x x that becomes a child of y y y , decreases by one for nodes outside the subtree formerly rooted at y y y , and is unchanged otherwise. As search i i i begins with the pointer at the root, at distance d T i ( x i ) d_{T_i}(x_i) d T i ( x i ) from x i x_i x i , the pointer must touch x i x_i x i and search i i i using at least d T i ( x i ) d_{T_i}(x_i) d T i ( x i ) unit-cost operations. Thus
A ( A , T 0 , X ) ≥ ∑ i ∈ n o t F i r s t log 1 α n min ( x i , n − x i + 1 ) − m . A(A,T_0,X)\ge\sum_{i\in\mathrm{notFirst}}\log\frac{1}{\alpha}\frac{n}{\min(x_i,n-x_i+1)}-m. A ( A , T 0 , X ) ≥ i ∈ notFirst ∑ log α 1 min ( x i , n − x i + 1 ) n − m . The first term: This is a manipulation of Lemma 16:
A ( A , T 0 , X ) ≥ 1 4 ∣ { ( i , ℓ ) ∣ i ∈ n o t F i r s t and x prev i ( γ ( ℓ ) ) ≠ x i } ∣ A(A,T_0,X)\ge\frac{1}{4}\left|\left\{(i,\ell)\mid i\in\mathrm{notFirst}\text{ and }x_{\operatorname{prev}_i}(\gamma(\ell))\ne x_i\right\}\right| A ( A , T 0 , X ) ≥ 4 1 { ( i , ℓ ) ∣ i ∈ notFirst and x prev i ( γ ( ℓ )) = x i } = 1 4 ∑ i ∈ n o t F i r s t ∣ { ℓ ∣ x prev i ( γ ( ℓ ) ) ≠ x i } ∣ . =\frac{1}{4}\sum_{i\in\mathrm{notFirst}}\left|\left\{\ell\mid x_{\operatorname{prev}_i}(\gamma(\ell))\ne x_i\right\}\right|. = 4 1 i ∈ notFirst ∑ { ℓ ∣ x prev i ( γ ( ℓ )) = x i } .
Observe that if x prev i ( γ ( ℓ ) ) ≠ x i x_{\operatorname{prev}_i(\gamma(\ell))} \ne x_i x prev i ( γ ( ℓ )) = x i then prev i ( γ ( ℓ ) ) > prev i \operatorname{prev}_i(\gamma(\ell)) > \operatorname{prev}_i prev i ( γ ( ℓ )) > prev i (Lemma 14), and thus the same holds for all smaller nonnegative integer values of ℓ \ell ℓ . Note that γ \gamma γ is decreasing in ℓ \ell ℓ and prev i ( r ) \operatorname{prev}_i(r) prev i ( r ) is nondecreasing in r r r , so prev i ( γ ( ℓ ′ ) ) ≥ prev i ( γ ( ℓ ) ) > prev i \operatorname{prev}_i(\gamma(\ell')) \ge\operatorname{prev}_i(\gamma(\ell)) > \operatorname{prev}_i prev i ( γ ( ℓ ′ )) ≥ prev i ( γ ( ℓ )) > prev i for all ℓ ′ ≤ ℓ \ell' \le\ell ℓ ′ ≤ ℓ , and no search at a time in ( prev i , i ) (\operatorname{prev}_i,i) ( prev i , i ) is a search of x i x_i x i . The set { ℓ ∣ x prev i ( γ ( ℓ ) ) ≠ x i } \{\ell\mid x_{\operatorname{prev}_i(\gamma(\ell))} \ne x_i\} { ℓ ∣ x prev i ( γ ( ℓ )) = x i } is therefore downward closed, and its size is precisely the smallest ℓ \ell ℓ such that x prev i ( γ ( ℓ ) ) = x i x_{\operatorname{prev}_i(\gamma(\ell))}=x_i x prev i ( γ ( ℓ )) = x i , which we denote k i k_i k i . This is well defined because for large enough ℓ \ell ℓ , γ ( ℓ ) < 1 \gamma(\ell)<1 γ ( ℓ ) < 1 and the only integer in [ x i − γ ( ℓ ) , x i + γ ( ℓ ) ] [x_i-\gamma(\ell),x_i+\gamma(\ell)] [ x i − γ ( ℓ ) , x i + γ ( ℓ )] is x i x_i x i itself, from which prev i ( γ ( ℓ ) ) = prev i \operatorname{prev}_i(\gamma(\ell))=\operatorname{prev}_i prev i ( γ ( ℓ )) = prev i .
= 1 4 ∑ i ∈ n o t F i r s t k i = \frac{1}{4}\sum_{i\in\mathrm{notFirst}} k_i = 4 1 i ∈ notFirst ∑ k i
It remains to relate k i k_i k i to the minimization over r r r in the statement of the theorem. Let
r i : = n γ ( k i ) = ( 1 α ) k i + 1 log α β . r_i := \frac{n}{\gamma(k_i)} = \left(\frac{1}{\alpha}\right)^{\frac{k_i+1}{\log_\alpha\beta}}. r i := γ ( k i ) n = ( α 1 ) l o g α β k i + 1 .
Then r i ≥ 1 r_i \ge1 r i ≥ 1 and x prev i ( n / r i ) = x prev i ( γ ( k i ) ) = x i x_{\operatorname{prev}_i(n/r_i)}=x_{\operatorname{prev}_i(\gamma(k_i))}=x_i x prev i ( n / r i ) = x prev i ( γ ( k i )) = x i , so r i r_i r i is a candidate in the minimization and
min { r ≥ 1 ∣ x prev i ( n / r ) = x i } ≤ r i = ( 1 α ) k i + 1 log α β . \min\left\{r\ge1 \mid x_{\operatorname{prev}_i(n/r)}=x_i\right\}\le r_i=\left(\frac{1}{\alpha}\right)^{\frac{k_i+1}{\log_\alpha\beta}}. min { r ≥ 1 ∣ x prev i ( n / r ) = x i } ≤ r i = ( α 1 ) l o g α β k i + 1 .
Taking log 1 α \log_{\frac{1}{\alpha}} log α 1 of both sides and rearranging gives
k i ≥ log α β ⋅ log 1 α min { r ≥ 1 ∣ x prev i ( n / r ) = x i } − 1. k_i \ge\log_\alpha\beta\cdot\log_{\frac{1}{\alpha}}\min\left\{r\ge1 \mid x_{\operatorname{prev}_i(n/r)}=x_i\right\}-1. k i ≥ log α β ⋅ log α 1 min { r ≥ 1 ∣ x prev i ( n / r ) = x i } − 1.
Summing over i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst and using ∣ n o t F i r s t ∣ ≤ m |\mathrm{notFirst}|\le m ∣ notFirst ∣ ≤ m ,
A ( A , T 0 , X ) ≥ 1 4 ∑ i ∈ n o t F i r s t k i ≥ log α β 4 S 1 − m 4 , where S 1 : = ∑ i ∈ n o t F i r s t log 1 α min { r ≥ 1 ∣ x prev i ( n / r ) = x i } . A(\mathcal{A},T_0,X)\ge\frac{1}{4}\sum_{i\in\mathrm{notFirst}}k_i
\ge\frac{\log_\alpha\beta}{4}S_1-\frac{m}{4},
\qquad\text{where }S_1:=\sum_{i\in\mathrm{notFirst}}\log_{\frac{1}{\alpha}}\min\left\{r\ge1\mid x_{\operatorname{prev}_i(n/r)}=x_i\right\}. A ( A , T 0 , X ) ≥ 4 1 i ∈ notFirst ∑ k i ≥ 4 log α β S 1 − 4 m , where S 1 := i ∈ notFirst ∑ log α 1 min { r ≥ 1 ∣ x prev i ( n / r ) = x i } .
Combining: Let S 2 : = ∑ i ∈ n o t F i r s t log 1 α n min ( x i , n − x i + 1 ) S_2:=\sum_{i\in\mathrm{notFirst}}\log_{\frac{1}{\alpha}}\frac{n}{\min(x_i,n-x_i+1)} S 2 := ∑ i ∈ notFirst log α 1 m i n ( x i , n − x i + 1 ) n , so that the second-term bound reads A ( A , T 0 , X ) ≥ S 2 − m A(\mathcal{A},T_0,X)\ge S_2-m A ( A , T 0 , X ) ≥ S 2 − m . Both S 1 S_1 S 1 and S 2 S_2 S 2 are nonnegative. Each term of S 1 S_1 S 1 is at least log 1 α 1 = 0 \log_{\frac{1}{\alpha}}1=0 log α 1 1 = 0 by the restriction r ≥ 1 r\ge1 r ≥ 1 , and each term of S 2 S_2 S 2 is nonnegative as min ( x i , n − x i + 1 ) ≤ n \min(x_i,n-x_i+1)\le n min ( x i , n − x i + 1 ) ≤ n . Trivially A ( A , T 0 , X ) ≥ m A(\mathcal{A},T_0,X)\ge m A ( A , T 0 , X ) ≥ m , as each search uses at least one unit-cost operation. Taking 4 5 \frac{4}{5} 5 4 of the first-term bound plus 1 5 \frac{1}{5} 5 1 of the trivial bound gives
A ( A , T 0 , X ) ≥ 4 5 ( log α β 4 S 1 − m 4 ) + 1 5 m = log α β 5 S 1 , A(\mathcal{A},T_0,X)\ge\frac{4}{5}\left(\frac{\log_\alpha\beta}{4}S_1-\frac{m}{4}\right)+\frac{1}{5}m=\frac{\log_\alpha\beta}{5}S_1, A ( A , T 0 , X ) ≥ 5 4 ( 4 log α β S 1 − 4 m ) + 5 1 m = 5 log α β S 1 ,
and taking half of the second-term bound plus half of the trivial bound gives A ≥ 1 2 S 2 A\ge\frac{1}{2}S_2 A ≥ 2 1 S 2 . Averaging these two bounds,
A ( A , T 0 , X ) ≥ log α β 10 S 1 + 1 4 S 2 ≥ log α β 10 ( S 1 + S 2 ) . A(\mathcal{A},T_0,X)\ge\frac{\log_\alpha\beta}{10}S_1+\frac{1}{4}S_2\ge\frac{\log_\alpha\beta}{10}(S_1+S_2). A ( A , T 0 , X ) ≥ 10 log α β S 1 + 4 1 S 2 ≥ 10 log α β ( S 1 + S 2 ) .
As α \alpha α is constant, log 1 α \log_{\frac{1}{\alpha}} log α 1 and log \log log agree up to a constant factor, and thus A ( A , T 0 , X ) = Ω ( O P T ( X ) ) A(\mathcal{A},T_0,X)=\Omega(OPT(X)) A ( A , T 0 , X ) = Ω ( O P T ( X )) .
Upper Bound
In this section, we begin by defining the SkipPopList, which is a variant of the skip-list data structure of Pugh [34 ] . After proving SkipPopList has a running time of O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) , in the following subsections we will show how via a detailed transform drawn from [21 ] to our BST algorithm, the PopTree, a B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -algorithm with a running time of O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) can be obtained. This transformation does not proceed directly but rather via a multiway search tree, which we call the PopBTree. The SkipPopList is the most interesting part, as the transformations are largely standard but require somewhat tedious arguments to ensure that constant balance is preserved every step of the way. In the transform from SkipPopList to the PopBTree, one nontrivial detail is that in a SkipPopList, one can move freely left and right in a level. However, in the PopBTree, only parent and child pointers are present. Hence, an argument that one can effectuate the specific changes of the SkipPopList without blowing up the running time needs to be presented.
SkipPopList
The structure is defined over a static set of data of size n n n , which, for convenience, we assume to be a power of three and which contains the integers in [ n ] [n] [ n ] .
Skip list. We begin with the usual ingredients of a Skip List:
There are levels, which we number from the top down, starting at level 1. Note that the concept of level used when discussing skip lists is different from that in the previous section, which applies to trees.
Each level stores a subset of the data.
Level ℓ \ell ℓ stores a subset of the data in level ℓ + 1 \ell+ 1 ℓ + 1 .
There is a level ℓ max \ell_{\max} ℓ m a x which stores [ n ] [n] [ n ] , all the data.
The level of an item, ℓ ( x ) \ell(x) ℓ ( x ) is the smallest level that it appears in.
Skip list cost model. We make the skip list cost model precise. There is a single pointer that always points to an item in a particular level and starts each search at the smallest-valued item in level 1. At unit cost, the pointer can move to the predecessor or the successor on the current level, or stay with the same item and move up or down a level, so long as the item is present in the destination level. Additionally, if the pointer points to the top most level an item belongs to, it may demote the item which involves removing the item from that level and moving the pointer down one level. Items in ℓ max \ell_{\max} ℓ m a x can not be demoted. The inverse operation of promotion is also allowed, which inserts the item into the level above and moves the pointer up, and is permitted only when the pointer is at the item’s topmost level, and it is not already at level 1. A skip list successfully executes a search for x i x_i x i if the pointer touches a node containing x i x_i x i at any level during the execution of the search.
SkipPopList Invariants. We now describe the basic structural invariants of a SkipPopList.
In level ℓ \ell ℓ we view all keys (all of them, not just the ones stored at that level) as being partitioned into 3 ℓ 3^\ell 3 ℓ buckets . The 3 ℓ 3^\ell 3 ℓ buckets each contain n / 3 ℓ n/3^\ell n / 3 ℓ consecutive keys. We adopt the tree terminology of sibling, parent, and child. In general, a bucket has two sibling buckets, a parent bucket (above) and three child buckets (below).
Each bucket at level ℓ \ell ℓ is either disjoint from the items stored at level ℓ \ell ℓ , which we refer to as vacant , or the bucket intersects a single item stored at level ℓ \ell ℓ in which case we refer to it as occupied .
No adjacent buckets on the same level can be occupied
At most two consecutive buckets on the same level can be vacant.
The minimum and maximum buckets on every level must be vacant, these are referred to as the extreme buckets.
See Figure 1 for an illustration. The SkipPopList structure also has temporal invariants with respect to a sequence of searches being performed on items in [ n ] [n] [ n ] . These invariants are the most novel part of our construction. Intuitively, they require recently searched items that do not have a more recently searched item nearby to be in lower-numbered levels as a function of “nearby” and “recently,” but yet give flexibility to allow rebalancing to work.
Each nonextreme bucket is either important or unimportant . Extreme buckets are simply extreme and must be vacant.
A nonextreme bucket is important if its most recently searched item was searched more recently than the most recently searched items in its two sibling buckets.
An important bucket must be occupied by the most recently accessed item in the bucket.
Unimportant buckets may be either occupied or vacant and if they are occupied there is no requirement on which item occupies it.
The bottom level. Set ℓ max : = log 3 n + 1 \ell_{\max} := \log_{3} n + 1 ℓ m a x := log 3 n + 1 . For levels ℓ ≤ log 3 n \ell\le\log_{3} n ℓ ≤ log 3 n the buckets are as defined above: 3 ℓ 3^{\ell} 3 ℓ buckets of n 3 ℓ \frac{n}{3^{\ell}} 3 ℓ n consecutive keys each. In particular, at level log 3 n \log_{3} n log 3 n each bucket consists of a single key. At level ℓ max \ell_{\max} ℓ m a x there are 3 n 3n 3 n buckets, three children per level-( log 3 n ) (\log_{3} n) ( log 3 n ) bucket. The key of the parent bucket belongs to the middle child, and the two outer children contain no keys. Level ℓ max \ell_{\max} ℓ m a x stores all of [ n ] [n] [ n ] . (Assigning keys by the natural subdivision of key ranges would instead place each key in an outer child, and in particular place key n n n in the maximum bucket of level ℓ max \ell_{\max} ℓ m a x , violating the requirement that extreme buckets be vacant, hence the middle-child convention.)
Assorted observations
Lemma 18. The bottom level The occupancy of level ℓ max = log 3 n + 1 \ell_{\max} = \log_{3} n + 1 ℓ m a x = log 3 n + 1 is fully determined, i.e., the middle child of each level-( log 3 n ) (\log_{3} n) ( log 3 n ) bucket is occupied by that bucket’s key, and every other bucket is vacant, so exactly every third bucket is occupied. This occupancy satisfies all SkipPopList invariants and never changes during the execution of any search sequence.
Proof. Level ℓ max \ell_{\max} ℓ m a x stores all of [ n ] [n] [ n ] and each key belongs to the middle child of its parent, so the occupied buckets are exactly the n n n middle children. The outer children contain no keys and are therefore permanently vacant. Read left to right, the level has the pattern, vacant, occupied, vacant, repeated n n n times.
We verify the invariants. Every occupied bucket contains exactly one stored item, its key. Consecutive occupied buckets are separated by exactly two vacant buckets, so no two adjacent buckets are occupied, and no three consecutive buckets are vacant. The minimum and maximum buckets are outer children and thus vacant. For the temporal invariants, each occupied bucket contains a single item, which is therefore its most recently searched item whenever any of its items has been searched, and its sibling buckets contain no keys. So an important bucket at level ℓ max \ell_{\max} ℓ m a x is always occupied by its most recently searched item.
Finally, the occupancy never changes. Promotions insert an item into a level above its topmost level and remove nothing from the levels below. A demotion at a level removes the occupant of a bucket that contains, or is adjacent to, the bucket containing the searched key at that level. At level ℓ max \ell_{\max} ℓ m a x , the buckets adjacent to the searched key’s bucket contain no keys and are permanently vacant, and distinct keys occupy buckets at a distance of at least three. So no conflict ever arises at level ℓ max \ell_{\max} ℓ m a x and no clearing cascade ever demotes an item from it.
Lemma 19. For any bucket b b b at level ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x , at least one of the three child buckets of b b b at level ℓ + 1 \ell+ 1 ℓ + 1 is occupied. Moreover, if b b b is vacant, the occupant of any occupied child bucket of b b b has ℓ + 1 \ell+ 1 ℓ + 1 as its topmost level.
Proof. The three child buckets of b b b are consecutive at level ℓ + 1 \ell+ 1 ℓ + 1 and partition the keys of b b b . By Invariant 9, they cannot all be vacant, so at least one is occupied. For the second claim, if the occupant w w w of an occupied child bucket were stored at some level ℓ ′ ≤ ℓ \ell' \le\ell ℓ ′ ≤ ℓ , then by the subset property, w w w would be stored at level ℓ \ell ℓ . As w w w ’s key lies in b b b , bucket b b b would then be occupied, a contradiction.
Lemma 20. Let i ∈ n o t F i r s t i \in\mathit{notFirst} i ∈ notFirst and let ℓ \ell ℓ be a level, 1 ≤ ℓ ≤ ℓ max 1 \le\ell\le\ell_{\max} 1 ≤ ℓ ≤ ℓ m a x . If x p r e v i ( 2 n 3 ℓ ) = x i x_{\mathrm{prev}_i(\frac{2n}{3^\ell})} = x_i x prev i ( 3 ℓ 2 n ) = x i and min ( x i , n − x i + 1 ) > n 3 ℓ \min(x_i,n-x_i+1) > \frac{n}{3^\ell} min ( x i , n − x i + 1 ) > 3 ℓ n , then x i x_i x i is stored in level ℓ \ell ℓ of the SkipPopList just before the execution of the i i i th search.
Proof. Since min ( x i , n − x i + 1 ) > n 3 ℓ \min(x_i,n-x_i+1) > \frac{n}{3^\ell} min ( x i , n − x i + 1 ) > 3 ℓ n we have x i > n 3 ℓ x_i > \frac{n}{3^\ell} x i > 3 ℓ n and x i ≤ n − n 3 ℓ x_i \le n-\frac{n}{3^\ell} x i ≤ n − 3 ℓ n , so x i x_i x i lies in neither the minimum nor the maximum bucket of level ℓ \ell ℓ . Therefore, its level-ℓ \ell ℓ bucket is not extreme.
The range [ x i − 2 n 3 ℓ , x i + 2 n 3 ℓ ] \left[x_i-\frac{2n}{3^\ell},x_i+\frac{2n}{3^\ell}\right] [ x i − 3 ℓ 2 n , x i + 3 ℓ 2 n ] includes all keys of the size-n 3 ℓ \frac{n}{3^\ell} 3 ℓ n level-ℓ \ell ℓ bucket containing x i x_i x i as well as all keys of that bucket’s two sibling buckets. As x p r e v i ( 2 n 3 ℓ ) = x i x_{\mathrm{prev}_i(\frac{2n}{3^\ell})}=x_i x prev i ( 3 ℓ 2 n ) = x i means x i x_i x i is the most recently searched item in [ x i − 2 n 3 ℓ , x i + 2 n 3 ℓ ] \left[x_i-\frac{2n}{3^\ell},x_i+\frac{2n}{3^\ell}\right] [ x i − 3 ℓ 2 n , x i + 3 ℓ 2 n ] before time i i i , it is the most recently searched item in its bucket and more recently searched than any item in the two sibling buckets. Its bucket is therefore important, and by the temporal invariants an important bucket is occupied by its most recently searched item, namely x i x_i x i . Hence x i x_i x i is stored in level ℓ \ell ℓ .
Lemma 21. Given an i ∈ n o t F i r s t i \in\mathit{notFirst} i ∈ notFirst , let ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) be the minimum level of x i x_i x i in the SkipPopList before the execution of the i i i th operation. We have
ℓ i ( x i ) ≤ max ( log 3 min { r ≥ 1 ∣ x p r e v i ( n 3 r ) = x i } , log 3 n min ( x i , n − x i + 1 ) ) + 3 \ell_i(x_i) \le\max\left(\log_3\min\left\{r \ge1 \mid x_{\mathrm{prev}_i(\frac{n}{3^r})}=x_i\right\},\log_3\frac{n}{\min(x_i,n-x_i+1)}\right)+3 ℓ i ( x i ) ≤ max ( log 3 min { r ≥ 1 ∣ x prev i ( 3 r n ) = x i } , log 3 min ( x i , n − x i + 1 ) n ) + 3 Proof. Follows from Lemma 20 and some math. Throughout, ℓ \ell ℓ ranges over the nonnegative integers both conditions of Lemma 20 are upward closed in ℓ \ell ℓ (shrinking the range of p r e v i \mathrm{prev}_i prev i preserves x i x_i x i being most recent, and n 3 ℓ \frac{n}{3^\ell} 3 ℓ n is decreasing), ℓ = 0 \ell=0 ℓ = 0 fails the second condition as min ( x i , n − x i + 1 ) ≤ n \min(x_i,n-x_i+1)\le n min ( x i , n − x i + 1 ) ≤ n , and if the minimum below exceeds ℓ max \ell_{\max} ℓ m a x the first inequality holds trivially since ℓ i ( x i ) ≤ ℓ max \ell_i(x_i)\le\ell_{\max} ℓ i ( x i ) ≤ ℓ m a x .
ℓ i ( x i ) ≤ min ( x p r e v i ( 2 n 3 ℓ ) = x i and min ( x i , n − x i + 1 ) > n 3 ℓ ) \ell_i(x_i) \le\min\left(x_{\mathrm{prev}_i(\frac{2n}{3^\ell})}=x_i\ \text{and}\ \min(x_i,n-x_i+1)>\frac{n}{3^\ell}\right) ℓ i ( x i ) ≤ min ( x prev i ( 3 ℓ 2 n ) = x i and min ( x i , n − x i + 1 ) > 3 ℓ n ) By upward closure, this is the maximum level where the condition fails, plus one:
= 1 + max ( x p r e v i ( 2 n 3 ℓ ) ≠ x i or min ( x i , n − x i + 1 ) ≤ n 3 ℓ ) =1+\max\left(x_{\mathrm{prev}_i(\frac{2n}{3^\ell})}\ne x_i\ \text{or}\ \min(x_i,n-x_i+1)\le\frac{n}{3^\ell}\right) = 1 + max ( x prev i ( 3 ℓ 2 n ) = x i or min ( x i , n − x i + 1 ) ≤ 3 ℓ n ) = 1 + max ( max ℓ x p r e v i ( 2 n 3 ℓ ) ≠ x i , max ℓ [ ℓ ≤ log 3 n min ( x i , n − x i + 1 ) ] ) =1+\max\left(\max_\ell x_{\mathrm{prev}_i(\frac{2n}{3^\ell})}\ne x_i,\ \max_\ell\left[\ell\le\log_3\frac{n}{\min(x_i,n-x_i+1)}\right]\right) = 1 + max ( ℓ max x prev i ( 3 ℓ 2 n ) = x i , ℓ max [ ℓ ≤ log 3 min ( x i , n − x i + 1 ) n ] ) Since ℓ \ell ℓ is an integer, max ℓ [ ℓ ≤ a ] = ⌊ a ⌋ ≤ a \max_\ell[\ell\le a]=\lfloor a\rfloor\le a max ℓ [ ℓ ≤ a ] = ⌊ a ⌋ ≤ a .
≤ 1 + max ( max ℓ x p r e v i ( 2 n 3 ℓ ) ≠ x i , log 3 n min ( x i , n − x i + 1 ) ) \le1+\max\left(\max_\ell x_{\mathrm{prev}_i(\frac{2n}{3^\ell})}\ne x_i,\ \log_3\frac{n}{\min(x_i,n-x_i+1)}\right) ≤ 1 + max ( ℓ max x prev i ( 3 ℓ 2 n ) = x i , log 3 min ( x i , n − x i + 1 ) n ) The maximum integer where something fails is the minimum where it holds, minus one.
= 1 + max ( − 1 + min ℓ x p r e v i ( 2 n 3 ℓ ) = x i , log 3 n min ( x i , n − x i + 1 ) ) =1+\max\left(-1+\min_\ell x_{\mathrm{prev}_i(\frac{2n}{3^\ell})}=x_i,\ \log_3\frac{n}{\min(x_i,n-x_i+1)}\right) = 1 + max ( − 1 + ℓ min x prev i ( 3 ℓ 2 n ) = x i , log 3 min ( x i , n − x i + 1 ) n )
We now allow the level variable to be a nonnegative real, denoted ℓ ^ \hat{\ell} ℓ ^ , to be more flexible with the math. As the condition is upward closed, the minimum over the integers exceeds the minimum over the reals by at most one, so:
≤ 1 + max ( min { ℓ ^ ∣ x prev i ( 2 n 3 ℓ ) = x i } , log 3 n min ( x i , n − x i + 1 ) ) \le1+\max\left(\min\left\{\hat{\ell}\mid x_{\operatorname{prev}_{i}\left(\frac{2n}{3^{\ell}}\right)}=x_i\right\},\log_{3}\frac{n}{\min(x_i,n-x_i+1)}\right) ≤ 1 + max ( min { ℓ ^ ∣ x prev i ( 3 ℓ 2 n ) = x i } , log 3 min ( x i , n − x i + 1 ) n )
As ℓ ^ = log 3 3 ℓ ^ 2 + log 3 2 \hat{\ell}=\log_{3}\frac{3^{\hat{\ell}}}{2}+\log_{3}2 ℓ ^ = log 3 2 3 ℓ ^ + log 3 2 and 3 ℓ ^ 2 \frac{3^{\hat{\ell}}}{2} 2 3 ℓ ^ is monotone increasing in ℓ ^ \hat{\ell} ℓ ^ :
= 1 + max ( log 3 min { 3 ℓ ^ 2 ∣ x prev i ( 2 n 3 ℓ ) = x i } + log 3 2 , log 3 n min ( x i , n − x i + 1 ) ) =1+\max\left(\log_{3}\min\left\{\frac{3^{\hat{\ell}}}{2}\mid x_{\operatorname{prev}_{i}\left(\frac{2n}{3^{\ell}}\right)}=x_i\right\}+\log_{3}2,\log_{3}\frac{n}{\min(x_i,n-x_i+1)}\right) = 1 + max ( log 3 min { 2 3 ℓ ^ ∣ x prev i ( 3 ℓ 2 n ) = x i } + log 3 2 , log 3 min ( x i , n − x i + 1 ) n )
Set r = 3 ℓ ^ 2 r=\frac{3^{\hat{\ell}}}{2} r = 2 3 ℓ ^ , so 2 n 3 ℓ ^ = n r \frac{2n}{3^{\hat{\ell}}}=\frac{n}{r} 3 ℓ ^ 2 n = r n . As ℓ ^ \hat{\ell} ℓ ^ ranges over the nonnegative reals, r r r ranges over [ 1 2 , ∞ ) \left[\frac{1}{2},\infty\right) [ 2 1 , ∞ ) . Further restricting to r ≥ 1 r\ge1 r ≥ 1 can only increase the minimum. Using 1 + log 3 2 < 2 < 3 1+\log_{3}2<2<3 1 + log 3 2 < 2 < 3 :
≤ max ( log 3 min { r ≥ 1 ∣ x prev i ( n r ) = x i } , log 3 n min ( x i , n − x i + 1 ) ) + 3 \le\max\left(\log_{3}\min\left\{r\ge1\mid x_{\operatorname{prev}_{i}\left(\frac{n}{r}\right)}=x_i\right\},\log_{3}\frac{n}{\min(x_i,n-x_i+1)}\right)+3 ≤ max ( log 3 min { r ≥ 1 ∣ x prev i ( r n ) = x i } , log 3 min ( x i , n − x i + 1 ) n ) + 3
Thus we can conclude that the sum of all depths of searched nodes is asymptotically the same as the lower bound of O ( OPT ( X ) ) O(\operatorname{OPT}(X)) O ( OPT ( X )) .
Corollary 22. Depth sums. For any search sequence X X X of length Ω ( n log n ) \Omega(n\log n) Ω ( n log n )
∑ i ℓ i ( x i ) = O ( OPT ( X ) ) . \sum_i \ell_i(x_i)=O(\operatorname{OPT}(X)). i ∑ ℓ i ( x i ) = O ( OPT ( X )) .
Proof. First observe OPT ( X ) = Ω ( m ) \operatorname{OPT}(X)=\Omega(m) OPT ( X ) = Ω ( m ) . Each term of (1) is nonnegative, and its second summand is at least log n min ( x i , n − x i + 1 ) ≥ log 2 n n + 1 ≥ log 4 3 \log\frac{n}{\min(x_i,n-x_i+1)}\ge\log\frac{2n}{n+1}\ge\log\frac{4}{3} log m i n ( x i , n − x i + 1 ) n ≥ log n + 1 2 n ≥ log 3 4 for n ≥ 2 n\ge2 n ≥ 2 , so OPT ( X ) = Ω ( ∣ n o t F i r s t ∣ ) \operatorname{OPT}(X)=\Omega(\lvert\mathrm{notFirst}\rvert) OPT ( X ) = Ω (∣ notFirst ∣) . As ∣ n o t F i r s t ∣ ≥ m − n \lvert\mathrm{notFirst}\rvert\ge m-n ∣ notFirst ∣ ≥ m − n and m = Ω ( n log n ) m=\Omega(n\log n) m = Ω ( n log n ) , OPT ( X ) = Ω ( m ) \operatorname{OPT}(X)=\Omega(m) OPT ( X ) = Ω ( m ) .
For i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst , Lemma 21 bounds ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) by the maximum of two nonnegative quantities plus 3. The maximum is at most the sum, and as both arguments of the logarithms are at least 1, each base-3 logarithm is at most the corresponding base-2 logarithm, so the sum is at most the i i i th term of (1). Thus ∑ i ∈ n o t F i r s t ℓ i ( x i ) ≤ OPT ( X ) + 3 ∣ n o t F i r s t ∣ = O ( OPT ( X ) ) \sum_{i\in\mathrm{notFirst}}\ell_i(x_i)\le\operatorname{OPT}(X)+3\lvert\mathrm{notFirst}\rvert=O(\operatorname{OPT}(X)) ∑ i ∈ notFirst ℓ i ( x i ) ≤ OPT ( X ) + 3 ∣ notFirst ∣ = O ( OPT ( X )) .
Also ∑ i ∈ [ m ] ∖ n o t F i r s t ℓ i ( x i ) = O ( n log n ) \sum_{i\in[m]\setminus\mathrm{notFirst}}\ell_i(x_i)=O(n\log n) ∑ i ∈ [ m ] ∖ notFirst ℓ i ( x i ) = O ( n log n ) because there are at most n n n first searches and every item is at level at most ℓ max = O ( log n ) \ell_{\max}=O(\log n) ℓ m a x = O ( log n ) . Since OPT ( X ) = Ω ( m ) \operatorname{OPT}(X)=\Omega(m) OPT ( X ) = Ω ( m ) and m = Ω ( n log n ) m=\Omega(n\log n) m = Ω ( n log n ) , this is also O ( OPT ( X ) ) O(\operatorname{OPT}(X)) O ( OPT ( X )) .
Search algorithm
We have just completed the hard work of linking the depths of the searched items to OPT \operatorname{OPT} OPT . Now we just need to show that we can perform unit cost operations to maintain the invariants of the SkipPopList in time proportional to the depth of the item being searched. Fortunately, this is straightforward.
When executing a search sequence, changes need to be made to the structure to restore any temporal invariants that are now violated. In particular, after executing x i x_i x i , any non-extreme bucket that x i x_i x i belongs to becomes important and needs to have x i x_i x i as its representative.
Here is the method. Let t t t be the level at which the promotion of x i x_i x i will stop, the highest level whose bucket containing x i x_i x i is not extreme.
Clearing demotions. For each item y ≠ x i y \ne x_i y = x i , that at some level in [ t , ℓ i ( x i ) ) [t,\ell_i(x_i)) [ t , ℓ i ( x i )) , occupies either the bucket containing x i x_i x i or a bucket adjacent to it. We demote y y y repeatedly, starting at y y y ’s topmost level and proceeding downward, until y y y is no longer stored at any level at which its bucket contains, or is adjacent to, the bucket containing x i x_i x i ’s key. (The levels at which y y y conflicts form a contiguous range ending at some level c y < ℓ i ( x i ) c_y < \ell_i(x_i) c y < ℓ i ( x i ) , since buckets only grow when moving up. So this means demoting y y y until its topmost level is c y + 1 c_y + 1 c y + 1 .)
Gap repair. Wherever an item was demoted, if the resulting vacancy creates three consecutive vacant buckets on that level, promote into the middle of the three the occupant of one of its child buckets, which exists and has the level below as its topmost level by Lemma 19. This process should proceed in a bottom-up order.
Lemma 23. The above method restores all SkipPopList invariants.
Proof. We first consider the temporal invariants. After the search of x i x_i x i , the important buckets that change status are: every nonextreme bucket containing x i x_i x i becomes important (as x i x_i x i is now the most recently searched item overall), and every bucket adjacent to a bucket containing x i x_i x i ’s key, extreme or not, becomes unimportant. At levels ≥ ℓ i ( x i ) \ge\ell_i(x_i) ≥ ℓ i ( x i ) , x i x_i x i was already stored and hence already occupied every bucket containing it, and no adjacent bucket was occupied, so nothing needs to change there.
At levels [ t , ℓ i ( x i ) ) [t,\ell_i(x_i)) [ t , ℓ i ( x i )) , the promotion places x i x_i x i in every newly important bucket. Above level t t t , every bucket containing x i x_i x i ’s key is extreme (the ancestors of an extreme bucket are extreme) and thus exempt from importance. The clearing demotions remove items only from buckets that contain, or are adjacent to, the bucket containing x i x_i x i ’s key at that level. A vacated bucket adjacent to the bucket containing x i x_i x i ’s key is unimportant after the search of x i x_i x i , as a sibling now holds the most recently searched item, and unimportant buckets may be vacant. A vacated bucket that itself contains x i x_i x i ’s key can occur only at a level in [ t , ℓ i ( x i ) ) [t,\ell_i(x_i)) [ t , ℓ i ( x i )) because above t t t this bucket is extreme and hence vacant, and at levels ≥ ℓ i ( x i ) \ge\ell_i(x_i) ≥ ℓ i ( x i ) it is occupied by x i x_i x i itself. Such a bucket is important after the search, and the subsequent promotion phase fills it with x i x_i x i , its most recently searched item, restoring the invariant.
For the structural invariants, the clearing demotions ensure that when x i x_i x i is promoted into a bucket, that bucket is otherwise unoccupied and its neighbors are vacant, so occupancy-uniqueness and the no-adjacent-occupied invariant hold at every level x i x_i x i is promoted to. Demotions and gap-repair promotions never place two items in one bucket or occupy a bucket adjacent to an occupied one (the repaired bucket’s two neighbors are vacant by construction). Extreme buckets are never promoted, as promotion stops below them. Gap repair fills only a vacant bucket, both of whose neighbors are vacant, which is an extreme bucket, having a single neighbor.
Finally, since the invariants held before the search, after the demotions and the promotion of x i x_i x i , every maximal run of vacant buckets has length at most four. Moreover, a run of length four can arise only at a level above t t t , where it includes the extreme bucket containing the key of x i x_i x i . Each such run is eliminated by a gap-repair promotion into a vacant bucket, both of whose neighbors are vacant. At most two such promotions are needed per level. Each repaired bucket is unimportant after the search of x i x_i x i , so any occupied child’s occupant may be promoted into it. First, it does not contain x i x_i x i ’s key: at levels at least t t t that bucket is occupied by x i x_i x i . By the time gap repair runs, and repair fills only vacant buckets, while above level t t t , it is extreme, and extreme buckets are never repaired. If a sibling of the repaired bucket contains x i x_i x i ’s key, the repaired bucket is unimportant, as that sibling holds the most recently searched item. Otherwise, its importance status is unchanged by the search, and before the search, it was vacant, a bucket vacated by a demotion contains x i x_i x i ’s key or is adjacent to it, cases already excluded. Hence, unimportant, as important buckets must be occupied.
Lemma 24. In the skip list model, searching an item at level ℓ \ell ℓ and restoring the invariants of the SkipPopList takes time O ( ℓ ) O(\ell) O ( ℓ ) .
Proof. For the search, consecutive occupied buckets on any level are at most three buckets apart. So two consecutive items at level ℓ ′ \ell' ℓ ′ lie in a span of at most four consecutive buckets of level ℓ ′ \ell' ℓ ′ , and the key range between them is thus contained in at most twelve buckets of level ℓ ′ + 1 \ell' + 1 ℓ ′ + 1 , of which at most six are occupied, as no two adjacent buckets are occupied. Descending one level, therefore, requires at most a constant number of predecessor/successor moves, and reaching an item at level ℓ \ell ℓ takes O ( ℓ ) O(\ell) O ( ℓ ) time.
For the restoration, we bound the total number of unit-cost demotions and promotions. At each level, at most three buckets, the bucket containing x i x_i x i ’s key and its two neighbors can contain an occupant that must be demoted, and each gap repair performs one promotion adjacent to a demotion site. The promotion of x i x_i x i contributes one operation per level. Hence, the total number of structural operations is O ( ℓ ) O(\ell) O ( ℓ ) . Every operation site is within a constant number of buckets of the bucket containing x i x_i x i ’s key at its level, so moving the pointer between consecutive sites costs O ( 1 ) O(1) O ( 1 ) horizontal moves plus vertical moves. Since demotions themselves move the pointer down one level and promotions up one level, and the sites are processed in a single top-down pass per item, the total vertical movement is O ( ℓ ) O(\ell) O ( ℓ ) .
Lemma 25. Weak invariants during restoration. Consider the execution of the restoration method for the search of x i x_i x i , performed in the order: clearing demotions, then promotion of x i x_i x i , then gap repair. At every point during this execution (i.e., after every unit-cost operation) and at every level ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x :
no two adjacent buckets are occupied, and
at most seven consecutive buckets are vacant.
Proof. For a level ℓ \ell ℓ , let B ℓ B_\ell B ℓ denote the bucket at level ℓ \ell ℓ containing the key x i x_i x i , and let W ℓ W_\ell W ℓ consist of B ℓ B_\ell B ℓ together with its (at most two) sibling buckets, a window of at most three consecutive buckets. We first record the key structural fact: every demotion performed at level ℓ \ell ℓ removes the occupant of a bucket in W ℓ W_\ell W ℓ . Indeed, an item y y y is demoted from level ℓ \ell ℓ only during its top-down clearing cascade, and at every level at which y y y is demoted, its bucket contains, or is adjacent to, the bucket containing the key x i x_i x i , which lies in W ℓ W_\ell W ℓ . Consequently, any bucket outside W ℓ W_\ell W ℓ that was occupied before the search remains occupied throughout the execution, as demotions are the only operations that vacate buckets.
Claim 1. Occupancy is created only by promotions, of which there are two kinds. When x i x_i x i is promoted into B ℓ B_\ell B ℓ , the clearing phase has already vacated both siblings of B ℓ B_\ell B ℓ (any occupant of a sibling of B ℓ B_\ell B ℓ at a level into which x i x_i x i is promoted is, by definition, cleared), and no promotion refills them before the gap-repair phase. Hence, at the moment of promotion, both neighbors of B ℓ B_\ell B ℓ are vacant. A gap-repair promotion fills the middle bucket of three consecutive vacant buckets, so both neighbors of the filled bucket are vacant at that moment. (Note that an extreme bucket, having no neighbor on one side, is never the middle of three buckets and is thus never filled.) Demotions cannot create a pair of adjacent occupied buckets. Since no two adjacent buckets are occupied before the search, the property is preserved by every operation.
Claim 2. Fix a level ℓ \ell ℓ and any moment during the execution, consider a maximal run of consecutive vacant buckets at level ℓ \ell ℓ at that moment. By the invariants holding before the search, every maximal run of vacant buckets was then of length at most two. By the structural fact above,
every bucket outside W ℓ W_\ell W ℓ that bounds such a run remains occupied throughout. Hence, the run under consideration is contained in the union of at most two vacant buckets immediately to the left of W ℓ W_\ell W ℓ , the window W ℓ W_\ell W ℓ itself, and at most two vacant buckets immediately to the right of W ℓ W_\ell W ℓ , which gives at most 2 + 3 + 2 = 7 2+3+2=7 2 + 3 + 2 = 7 buckets in total.
Working Set
Let X = ⟨ x 1 , x 2 , … , x m ⟩ X=\langle x_1,x_2,\ldots,x_m\rangle X = ⟨ x 1 , x 2 , … , x m ⟩ be a search sequence and let f : [ n ] → [ n ] f:[n]\to[n] f : [ n ] → [ n ] be a uniformly random permutation. Let X ′ = f ( X ) = ⟨ x 1 ′ , x 2 ′ , … , x m ′ ⟩ X'=f(X)=\langle x'_1,x'_2,\ldots,x'_m\rangle X ′ = f ( X ) = ⟨ x 1 ′ , x 2 ′ , … , x m ′ ⟩ , where x i ′ = f ( x i ) x'_i=f(x_i) x i ′ = f ( x i ) . For any i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst we define, analogously to prev i ( r ) \operatorname{prev}_i(r) prev i ( r ) , a version that uses the transformed search sequence
prev i ′ ( r ) : = max { j ∈ [ i − 1 ] ∣ x j ′ ∈ [ x i ′ − r , x i ′ + r ] } . \operatorname{prev}'_i(r):=\max\{j\in[i-1]\mid x'_j\in[x'_i-r,x'_i+r]\}. prev i ′ ( r ) := max { j ∈ [ i − 1 ] ∣ x j ′ ∈ [ x i ′ − r , x i ′ + r ]} .
As f f f is a bijection, an item is searched for the first time at the same positions in X X X and X ′ X' X ′ . So the set n o t F i r s t \mathrm{notFirst} notFirst is the same for both sequences and prev i ′ ( r ) \operatorname{prev}'_i(r) prev i ′ ( r ) is well-defined for i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst since the previous search of x i x_i x i lies in every window.
For i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst , let W i : = { x j ∣ prev i ≤ j ≤ i } W_i:=\{x_j\mid\operatorname{prev}_i\le j\le i\} W i := { x j ∣ prev i ≤ j ≤ i } be the working set of x i x_i x i at time i i i , which is the set of distinct items searched from the previous search of x i x_i x i through time i i i . Let w ( x i ) : = ∣ W i ∣ w(x_i):=|W_i| w ( x i ) := ∣ W i ∣ be the working set number of x i x_i x i at time i i i (in this section w w w refers to working set and not weight). Note that x i ∈ W i x_i\in W_i x i ∈ W i , so w ( x i ) ≥ 1 w(x_i)\ge1 w ( x i ) ≥ 1 . Like n o t F i r s t \mathrm{notFirst} notFirst , the sets W i W_i W i and the numbers w ( x i ) w(x_i) w ( x i ) depend only on the access pattern and not on the key values, and thus are the same for X X X and X ′ X' X ′ .
Applying the definition of O P T OPT O P T , (1), to the permuted sequence X ′ X' X ′ gives:
O P T ( f ( X ) ) = ∑ i ∈ n o t F i r s t ( log min { r ≥ 1 ∣ x prev i ′ ( r / n ) ′ = x i ′ } + log n min ( x i ′ , n − x i ′ + 1 ) ) OPT(f(X))=\sum_{i\in\mathrm{notFirst}}\left(\log\min\left\{r\ge1\mid x'_{\operatorname{prev}'_i(r/n)}=x'_i\right\}+\log\frac{n}{\min(x'_i,n-x'_i+1)}\right) O P T ( f ( X )) = i ∈ notFirst ∑ ( log min { r ≥ 1 ∣ x prev i ′ ( r / n ) ′ = x i ′ } + log min ( x i ′ , n − x i ′ + 1 ) n )
Theorem 26. Let n ≥ 2 n\ge2 n ≥ 2 and let f : [ n ] → [ n ] f:[n]\to[n] f : [ n ] → [ n ] be a uniformly random permutation. Then, for any access sequence X X X of length m ≥ 2 n m\ge2n m ≥ 2 n ,
E f [ O P T ( f ( X ) ) ] = Θ ( m + ∑ i ∈ n o t F i r s t log w ( x i ) ) . \mathbb{E}_f[OPT(f(X))]=\Theta\left(m+\sum_{i\in\mathrm{notFirst}}\log w(x_i)\right). E f [ O P T ( f ( X ))] = Θ ( m + i ∈ notFirst ∑ log w ( x i ) ) .
Proof. For i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst , let
M i f : = min { r ≥ 1 ∣ x prev i ′ ( r / n ) ′ = x i ′ } . M_i^f:=\min\left\{r\ge1\mid x'_{\operatorname{prev}'_i(r/n)}=x'_i\right\}. M i f := min { r ≥ 1 ∣ x prev i ′ ( r / n ) ′ = x i ′ } .
Note that M i f M_i^f M i f is finite and for r > n r>n r > n the window [ x i ′ − r / n , x i ′ + r / n ] [x'_i-r/n,x'_i+r/n] [ x i ′ − r / n , x i ′ + r / n ] has radius less than 1 1 1 and so contains no key other than x i ′ x'_i x i ′ , hence prev i ′ ( r / n ) = prev i \operatorname{prev}'_i(r/n)=\operatorname{prev}_i prev i ′ ( r / n ) = prev i and the condition holds. By linearity of expectation,
E f [ O P T ( f ( X ) ) ] = ∑ i ∈ n o t F i r s t E [ log M i f ] + ∑ i ∈ n o t F i r s t E [ log n min ( x i ′ , n − x i ′ + 1 ) ] . \mathbb{E}_f[OPT(f(X))]=\sum_{i\in\mathrm{notFirst}}\mathbb{E}\left[\log M_i^f\right]+\sum_{i\in\mathrm{notFirst}}\mathbb{E}\left[\log\frac{n}{\min(x'_i,n-x'_i+1)}\right]. E f [ O P T ( f ( X ))] = i ∈ notFirst ∑ E [ log M i f ] + i ∈ notFirst ∑ E [ log min ( x i ′ , n − x i ′ + 1 ) n ] .
We evaluate each expectation separately.
Expectation of the second term: As f f f is a uniformly random permutation, the key x i ′ = f ( x i ) x'_i=f(x_i) x i ′ = f ( x i ) is uniformly distributed over [ n ] [n] [ n ] , meaning P ( x i ′ = k ) = 1 n \mathbb{P}(x'_i=k)=\frac{1}{n} P ( x i ′ = k ) = n 1 for all k ∈ [ n ] k\in[n] k ∈ [ n ] . So we have
E [ log n min ( x i ′ , n − x i ′ + 1 ) ] = 1 n ∑ k = 1 n log n min ( k , n − k + 1 ) \mathbb{E}\left[\log\frac{n}{\min(x'_i,n-x'_i+1)}\right]=\frac{1}{n}\sum_{k=1}^{n}\log\frac{n}{\min(k,n-k+1)} E [ log min ( x i ′ , n − x i ′ + 1 ) n ] = n 1 k = 1 ∑ n log min ( k , n − k + 1 ) n
We bound this summation from both sides by positive constants. For the lower bound, every k ∈ [ n ] k\in[n] k ∈ [ n ] satisfies min ( k , n − k + 1 ) ≤ n + 1 2 \min(k,n-k+1)\le\frac{n+1}{2} min ( k , n − k + 1 ) ≤ 2 n + 1 , so each of the n n n terms is at least log 2 n n + 1 ≥ log 4 3 \log\frac{2n}{n+1}\ge\log\frac{4}{3} log n + 1 2 n ≥ log 3 4 , using n ≥ 2 n\ge2 n ≥ 2 . For the upper bound, each value v ∈ [ 1 , ⌈ n 2 ⌉ ] v\in[1,\lceil\frac{n}{2}\rceil] v ∈ [ 1 , ⌈ 2 n ⌉] occurs as min ( k , n − k + 1 ) \min(k,n-k+1) min ( k , n − k + 1 ) for at most two values of k ∈ [ n ] k\in[n] k ∈ [ n ] , so
1 n ∑ k = 1 n log n min ( k , n − k + 1 ) ≤ 2 n ∑ v = 1 n log n v = 2 n log n n n ! ≤ 2 log e , \frac{1}{n}\sum_{k=1}^{n}\log\frac{n}{\min(k,n-k+1)}\le\frac{2}{n}\sum_{v=1}^{n}\log\frac{n}{v}=\frac{2}{n}\log\frac{n^n}{n!}\le2\log e, n 1 k = 1 ∑ n log min ( k , n − k + 1 ) n ≤ n 2 v = 1 ∑ n log v n = n 2 log n ! n n ≤ 2 log e ,
where the last inequality uses n ! ≥ ( n e ) n n!\ge\left(\frac{n}{e}\right)^n n ! ≥ ( e n ) n . Therefore the expectation is bounded above and below by positive constants:
E [ log n min ( x i ′ , n − x i ′ + 1 ) ] = Θ ( 1 ) \mathbb{E}\left[\log\frac{n}{\min(x'_i,n-x'_i+1)}\right]=\Theta(1) E [ log min ( x i ′ , n − x i ′ + 1 ) n ] = Θ ( 1 )
Summing over i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst yields a cost of Θ ( ∣ n o t F i r s t ∣ ) \Theta(|\mathrm{notFirst}|) Θ ( ∣ notFirst ∣ ) . As each item can be searched for the first time only once, ∣ n o t F i r s t ∣ ≥ m − n |\mathrm{notFirst}|\ge m-n ∣ notFirst ∣ ≥ m − n , and since m ≥ 2 n m\ge2n m ≥ 2 n we have m 2 ≤ ∣ n o t F i r s t ∣ ≤ m \frac{m}{2}\le|\mathrm{notFirst}|\le m 2 m ≤ ∣ notFirst ∣ ≤ m , the cumulative cost of the second term is therefore Θ ( m ) \Theta(m) Θ ( m ) .
Expectation of the first term: Fix i ∈ n o t F i r s t i\in\mathrm{notFirst} i ∈ notFirst . If w ( x i ) = 1 w(x_i)=1 w ( x i ) = 1 , then no item other than x i x_i x i is searched between times p r e v i \mathrm{prev}_i prev i and i i i , so x p r e v i ′ ( n / r ) ′ = x i ′ x'_{\mathrm{prev}'_i(n/r)}=x'_i x prev i ′ ( n / r ) ′ = x i ′ for every r ≥ 1 r\ge1 r ≥ 1 . Hence M i f = 1 M_i^f=1 M i f = 1 and E [ log M i f ] = 0 = log w ( x i ) \mathbb{E}[\log M_i^f]=0=\log w(x_i) E [ log M i f ] = 0 = log w ( x i ) . Assume for the remainder that w ( x i ) ≥ 2 w(x_i)\ge2 w ( x i ) ≥ 2 .
We first reduce the failure event to a geometric one. For any radius d ≥ 0 d\ge0 d ≥ 0 , the search at time p r e v i \mathrm{prev}_i prev i is to x i x_i x i , whose key x i ′ x'_i x i ′ lies in every window [ x i ′ − d , x i ′ + d ] [x'_i-d,x'_i+d] [ x i ′ − d , x i ′ + d ] , so p r e v i ′ ( d ) ≥ p r e v i \mathrm{prev}'_i(d)\ge\mathrm{prev}_i prev i ′ ( d ) ≥ prev i . Furthermore, by the definition of p r e v i \mathrm{prev}_i prev i , no search at time in ( p r e v i , i ) (\mathrm{prev}_i,i) ( prev i , i ) is to x i x_i x i . Therefore
x p r e v i ′ ( d ) ′ ≠ x i ′ ⟺ some item of W i ∖ { x i } is mapped by f into [ x i ′ − d , x i ′ + d ] . x'_{\mathrm{prev}'_i(d)}\ne x'_i\Longleftrightarrow\text{some item of }W_i\setminus\{x_i\}\text{ is mapped by }f\text{ into }[x'_i-d,x'_i+d]. x prev i ′ ( d ) ′ = x i ′ ⟺ some item of W i ∖ { x i } is mapped by f into [ x i ′ − d , x i ′ + d ] .
In particular, the set { r ≥ 1 ∣ x p r e v i ′ ( n / r ) ′ = x i ′ } \{r\ge1\mid x'_{\mathrm{prev}'_i(n/r)}=x'_i\} { r ≥ 1 ∣ x prev i ′ ( n / r ) ′ = x i ′ } is upward closed. As r r r grows the window shrinks, and an item of W i ∖ { x i } W_i\setminus\{x_i\} W i ∖ { x i } lying inside the smaller window also lies inside the larger one. Hence
2 ℓ < M i f ⟹ x p r e v i ′ ( n / 2 ℓ ) ′ ≠ x i ′ ⟹ 2 ℓ ≤ M i f . 2^\ell<M_i^f\Longrightarrow x'_{\mathrm{prev}'_i(n/2^\ell)}\ne x'_i\Longrightarrow2^\ell\le M_i^f. 2 ℓ < M i f ⟹ x prev i ′ ( n / 2 ℓ ) ′ = x i ′ ⟹ 2 ℓ ≤ M i f .
Next we discretize r r r using powers of two. For any real M ≥ 1 M\ge1 M ≥ 1 , the number of integers ℓ ≥ 0 \ell\ge0 ℓ ≥ 0 with 2 ℓ < M 2^\ell<M 2 ℓ < M is ⌈ log 2 M ⌉ \lceil\log_2M\rceil ⌈ log 2 M ⌉ , and the number with 2 ℓ ≤ M 2^\ell\le M 2 ℓ ≤ M is ⌊ log 2 M ⌋ + 1 \lfloor\log_2M\rfloor+1 ⌊ log 2 M ⌋ + 1 . Writing I I I for an indicator variable and combining with the implications above,
log M i f ≤ ∑ ℓ = 0 ∞ I [ x p r e v i ′ ( n / 2 ℓ ) ′ ≠ x i ′ ] ≤ log M i f + 1. \log M_i^f\le\sum_{\ell=0}^{\infty}I\left[x'_{\mathrm{prev}'_i(n/2^\ell)}\ne x'_i\right]\le\log M_i^f+1. log M i f ≤ ℓ = 0 ∑ ∞ I [ x prev i ′ ( n / 2 ℓ ) ′ = x i ′ ] ≤ log M i f + 1.
The sum is finite, as for 2 ℓ > n 2^\ell>n 2 ℓ > n the window has radius less than 1 1 1 and the indicator is 0 0 0 . Taking expectations and applying linearity of expectation,
E [ log M i f ] = ∑ ℓ = 0 ∞ P ℓ − θ i for some θ i ∈ [ 0 , 1 ] , where P ℓ : = P [ x p r e v i ′ ( n / 2 ℓ ) ′ ≠ x i ′ ] . \mathbb{E}\left[\log M_i^f\right]=\sum_{\ell=0}^{\infty}P_\ell-\theta_i\text{ for some }\theta_i\in[0,1],\qquad\text{where }P_\ell:=\mathbb{P}\left[x'_{\mathrm{prev}'_i(n/2^\ell)}\ne x'_i\right]. E [ log M i f ] = ℓ = 0 ∑ ∞ P ℓ − θ i for some θ i ∈ [ 0 , 1 ] , where P ℓ := P [ x prev i ′ ( n / 2 ℓ ) ′ = x i ′ ] .
By the reduction above, P ℓ P_{\ell} P ℓ is the probability that at least one of the w ( x i ) − 1 w(x_i)-1 w ( x i ) − 1 items of W i ∖ { x i } W_i \setminus\{x_i\} W i ∖ { x i } is mapped within distance n 2 ℓ \frac{n}{2^{\ell}} 2 ℓ n of x i ′ x_i' x i ′ . Conditioned on the value of x i ′ x_i' x i ′ , these items are assigned distinct keys uniformly at random, without replacement, from the n − 1 n-1 n − 1 keys other than x i ′ x_i' x i ′ .
We now divide the summation at the threshold ℓ ∗ = ⌊ log 2 w ( x i ) ⌋ \ell^* = \lfloor\log_2 w(x_i) \rfloor ℓ ∗ = ⌊ log 2 w ( x i )⌋ . Note ℓ ∗ ≥ 1 \ell^* \ge1 ℓ ∗ ≥ 1 as w ( x i ) ≥ 2 w(x_i) \ge2 w ( x i ) ≥ 2 :
∑ ℓ = 0 ∞ P ℓ = ∑ ℓ = 0 ℓ ∗ P ℓ + ∑ ℓ = ℓ ∗ + 1 ∞ P ℓ \sum_{\ell=0}^{\infty} P_{\ell} = \sum_{\ell=0}^{\ell^*} P_{\ell} + \sum_{\ell=\ell^*+1}^{\infty} P_{\ell} ℓ = 0 ∑ ∞ P ℓ = ℓ = 0 ∑ ℓ ∗ P ℓ + ℓ = ℓ ∗ + 1 ∑ ∞ P ℓ
We bound each of the summations:
When ℓ ≤ ℓ ∗ \ell\le\ell^* ℓ ≤ ℓ ∗ : We claim ∑ ℓ = 0 ℓ ∗ P ℓ = Θ ( log w ( x i ) ) \sum_{\ell=0}^{\ell^*} P_{\ell} = \Theta(\log w(x_i)) ∑ ℓ = 0 ℓ ∗ P ℓ = Θ ( log w ( x i )) . The upper bound is immediate as P ℓ ≤ 1 P_{\ell} \le1 P ℓ ≤ 1 and log 2 w ( x i ) ≥ 1 \log_2 w(x_i) \ge1 log 2 w ( x i ) ≥ 1 ,
∑ ℓ = 0 ℓ ∗ P ℓ ≤ ℓ ∗ + 1 ≤ log 2 w ( x i ) + 1 ≤ 2 log 2 w ( x i ) . \sum_{\ell=0}^{\ell^*} P_{\ell} \le\ell^* + 1 \le\log_2 w(x_i) + 1 \le2\log_2 w(x_i). ℓ = 0 ∑ ℓ ∗ P ℓ ≤ ℓ ∗ + 1 ≤ log 2 w ( x i ) + 1 ≤ 2 log 2 w ( x i ) .
For the lower bound, first observe that P 0 = 1 P_0 = 1 P 0 = 1 , the window of radius n n n contains all of [ n ] [n] [ n ] , and W i ∖ { x i } W_i \setminus\{x_i\} W i ∖ { x i } is nonempty. Now suppose ℓ ≤ ℓ ∗ − 2 \ell\le\ell^* - 2 ℓ ≤ ℓ ∗ − 2 , so that 2 ℓ + 2 ≤ w ( x i ) 2^{\ell+2} \le w(x_i) 2 ℓ + 2 ≤ w ( x i ) . The window [ x i ′ − n 2 ℓ , x i ′ + n 2 ℓ ] ∩ [ n ] \left[x_i' - \frac{n}{2^\ell}, x_i' + \frac{n}{2^\ell}\right] \cap[n] [ x i ′ − 2 ℓ n , x i ′ + 2 ℓ n ] ∩ [ n ] contains at least min ( n 2 ℓ , n − 1 ) ≥ n 2 ℓ + 1 \min(\frac{n}{2^\ell}, n-1) \ge\frac{n}{2^{\ell+1}} min ( 2 ℓ n , n − 1 ) ≥ 2 ℓ + 1 n keys other than x i ′ x_i' x i ′ (note 2 ℓ ≤ w ( x i ) ≤ n 2^\ell\le w(x_i) \le n 2 ℓ ≤ w ( x i ) ≤ n ), so a single item of W i ∖ { x i } W_i \setminus\{x_i\} W i ∖ { x i } lands in the window with probability at least n / 2 ℓ + 1 n − 1 ≥ 1 2 ℓ + 1 \frac{n/2^{\ell+1}}{n-1} \ge\frac{1}{2^{\ell+1}} n − 1 n / 2 ℓ + 1 ≥ 2 ℓ + 1 1 . As the items are placed without replacement, conditioning on earlier items missing the window only increases the fraction of remaining keys that lie inside it. The probability that all w ( x i ) − 1 w(x_i)-1 w ( x i ) − 1 items miss is therefore at most the product of the individual miss probabilities:
( 1 − 1 2 ℓ + 1 ) w ( x i ) − 1 ≤ e − w ( x i ) − 1 2 ℓ + 1 ≤ e − 1 , \left(1-\frac{1}{2^{\ell+1}}\right)^{w(x_i)-1} \le e^{-\frac{w(x_i)-1}{2^{\ell+1}}} \le e^{-1}, ( 1 − 2 ℓ + 1 1 ) w ( x i ) − 1 ≤ e − 2 ℓ + 1 w ( x i ) − 1 ≤ e − 1 ,
where the last inequality uses w ( x i ) − 1 ≥ w ( x i ) 2 ≥ 2 ℓ + 1 w(x_i)-1 \ge\frac{w(x_i)}{2} \ge2^{\ell+1} w ( x i ) − 1 ≥ 2 w ( x i ) ≥ 2 ℓ + 1 . Hence P ℓ ≥ 1 − e − 1 P_{\ell} \ge1-e^{-1} P ℓ ≥ 1 − e − 1 for all ℓ ≤ ℓ ∗ − 2 \ell\le\ell^* - 2 ℓ ≤ ℓ ∗ − 2 , and
∑ ℓ = 0 ℓ ∗ P ℓ ≥ max { 1 , ( 1 − e − 1 ) ( ℓ ∗ − 1 ) } ≥ 1 − e − 1 3 log 2 w ( x i ) , \sum_{\ell=0}^{\ell^*} P_{\ell} \ge\max\{1,(1-e^{-1})(\ell^*-1)\} \ge\frac{1-e^{-1}}{3}\log_2 w(x_i), ℓ = 0 ∑ ℓ ∗ P ℓ ≥ max { 1 , ( 1 − e − 1 ) ( ℓ ∗ − 1 )} ≥ 3 1 − e − 1 log 2 w ( x i ) ,
where the last inequality uses log 2 w ( x i ) ≤ ℓ ∗ + 1 ≤ 3 max { 1 , ℓ ∗ − 1 } \log_2 w(x_i) \le\ell^*+1 \le3\max\{1,\ell^*-1\} log 2 w ( x i ) ≤ ℓ ∗ + 1 ≤ 3 max { 1 , ℓ ∗ − 1 } .
When ℓ > ℓ ∗ \ell> \ell^* ℓ > ℓ ∗ : The window contains at most 2 n 2 ℓ \frac{2n}{2^\ell} 2 ℓ 2 n keys other than x i ′ x_i' x i ′ , so a single item of W i ∖ { x i } W_i \setminus\{x_i\} W i ∖ { x i } lands in the window with probability at most 2 n / 2 ℓ n − 1 ≤ 4 2 ℓ \frac{2n/2^\ell}{n-1} \le\frac{4}{2^\ell} n − 1 2 n / 2 ℓ ≤ 2 ℓ 4 (using n ≥ 2 n \ge2 n ≥ 2 , which follows from w ( x i ) ≥ 2 w(x_i) \ge2 w ( x i ) ≥ 2 ). By the union bound,
P ℓ ≤ 4 ( w ( x i ) − 1 ) 2 ℓ , P_{\ell} \le\frac{4(w(x_i)-1)}{2^\ell}, P ℓ ≤ 2 ℓ 4 ( w ( x i ) − 1 ) ,
and summing the geometric series,
∑ ℓ = ℓ ∗ + 1 ∞ P ℓ ≤ ∑ ℓ = ℓ ∗ + 1 ∞ 4 w ( x i ) 2 ℓ = 4 w ( x i ) 2 ℓ ∗ < 8 = O ( 1 ) , \sum_{\ell=\ell^*+1}^{\infty} P_{\ell} \le\sum_{\ell=\ell^*+1}^{\infty} \frac{4w(x_i)}{2^\ell} = \frac{4w(x_i)}{2^{\ell^*}} < 8 = O(1), ℓ = ℓ ∗ + 1 ∑ ∞ P ℓ ≤ ℓ = ℓ ∗ + 1 ∑ ∞ 2 ℓ 4 w ( x i ) = 2 ℓ ∗ 4 w ( x i ) < 8 = O ( 1 ) ,
using w ( x i ) < 2 ℓ ∗ + 1 w(x_i) < 2^{\ell^*+1} w ( x i ) < 2 ℓ ∗ + 1 .
Combining both ranges with the discretization error θ i ∈ [ 0 , 1 ] \theta_i \in[0,1] θ i ∈ [ 0 , 1 ] , we have, for w ( x i ) ≥ 2 w(x_i) \ge2 w ( x i ) ≥ 2 ,
E [ log M i f ] = Θ ( log w ( x i ) ) + O ( 1 ) , \mathbb{E}\left[\log M_i^f\right] = \Theta(\log w(x_i)) + O(1), E [ log M i f ] = Θ ( log w ( x i )) + O ( 1 ) ,
and since log 2 w ( x i ) ≥ 1 \log_{2} w(x_i) \ge1 log 2 w ( x i ) ≥ 1 , there are positive constants c 1 , C , C ′ c_1,C,C' c 1 , C , C ′ , independent of i i i , such that
c 1 log w ( x i ) − C ≤ E [ log M i f ] ≤ C ′ log w ( x i ) . c_1 \log w(x_i) - C \le\mathbb{E}\left[\log M_i^f\right] \le C' \log w(x_i). c 1 log w ( x i ) − C ≤ E [ log M i f ] ≤ C ′ log w ( x i ) .
These bounds also hold when w ( x i ) = 1 w(x_i) = 1 w ( x i ) = 1 , as then E [ log M i f ] = 0 = log w ( x i ) \mathbb{E}[\log M_i^f] = 0 = \log w(x_i) E [ log M i f ] = 0 = log w ( x i ) .
Combining the two terms: Let S : = ∑ i ∈ n o t F i r s t log w ( x i ) S := \sum_{i\in\mathrm{notFirst}} \log w(x_i) S := ∑ i ∈ notFirst log w ( x i ) . The upper bound is immediate:
E f [ O P T ( f ( X ) ) ] = ∑ i ∈ n o t F i r s t E [ log M i f ] + Θ ( m ) ≤ C ′ S + O ( m ) = O ( m + S ) . \mathbb{E}_f[\mathit{OPT}(f(X))] = \sum_{i\in\mathrm{notFirst}} \mathbb{E}\left[\log M_i^f\right] + \Theta(m) \le C'S + O(m) = O(m+S). E f [ OPT ( f ( X ))] = i ∈ notFirst ∑ E [ log M i f ] + Θ ( m ) ≤ C ′ S + O ( m ) = O ( m + S ) .
For the lower bound, both terms of (1) are nonnegative. The first by the restriction r ≥ 1 r \ge1 r ≥ 1 and the second as min ( x i ′ , n − x i ′ + 1 ) ≤ n \min(x'_i,n-x'_i+1) \le n min ( x i ′ , n − x i ′ + 1 ) ≤ n , so E f [ O P T ( f ( X ) ) ] \mathbb{E}_f[\mathit{OPT}(f(X))] E f [ OPT ( f ( X ))] is at least each of the two sums separately. The second sum gives, for some constant c 2 > 0 c_2 > 0 c 2 > 0 ,
E f [ O P T ( f ( X ) ) ] ≥ c 2 ∣ n o t F i r s t ∣ ≥ c 2 2 m , \mathbb{E}_f[\mathit{OPT}(f(X))] \ge c_2|\mathrm{notFirst}| \ge\frac{c_2}{2}m, E f [ OPT ( f ( X ))] ≥ c 2 ∣ notFirst ∣ ≥ 2 c 2 m ,
and the first sum gives
E f [ O P T ( f ( X ) ) ] ≥ ∑ i ∈ n o t F i r s t E [ log M i f ] ≥ c 1 S − C ∣ n o t F i r s t ∣ ≥ c 1 S − C m . \mathbb{E}_f[\mathit{OPT}(f(X))] \ge\sum_{i\in\mathrm{notFirst}} \mathbb{E}\left[\log M_i^f\right] \ge c_1S-C|\mathrm{notFirst}| \ge c_1S-Cm. E f [ OPT ( f ( X ))] ≥ i ∈ notFirst ∑ E [ log M i f ] ≥ c 1 S − C ∣ notFirst ∣ ≥ c 1 S − C m .
If c 1 S ≤ 2 C m c_1S \le2Cm c 1 S ≤ 2 C m , then S = O ( m ) S = O(m) S = O ( m ) and the first bound alone is Ω ( m + S ) \Omega(m+S) Ω ( m + S ) . Otherwise, c 1 S − C m ≥ c 1 2 S c_1S-Cm \ge\frac{c_1}{2}S c 1 S − C m ≥ 2 c 1 S , and the maximum of the two bounds is at least their average, which is Ω ( m + S ) \Omega(m+S) Ω ( m + S ) . In either case,
E f [ O P T ( f ( X ) ) ] = Ω ( m + ∑ i ∈ n o t F i r s t log w ( x i ) ) , \mathbb{E}_f[\mathit{OPT}(f(X))] = \Omega\left(m+\sum_{i\in\mathrm{notFirst}} \log w(x_i)\right), E f [ OPT ( f ( X ))] = Ω ( m + i ∈ notFirst ∑ log w ( x i ) ) ,
which together with the upper bound completes the proof. □
Acknowledgments
AI tools were used to critique proofs, identify bugs, mistakes, and inconsistencies. Specifically, Claude Fable and Opus were high-quality proofreaders that undoubtedly improved the paper’s quality and were particularly attentive to ensuring edge cases were handled correctly.
For the two transformations presented in sections A and B, given the tedious and non-innovative nature of these reductions, AI was used more aggressively and was given the sequence of lemmas in the manner that one would explain them to a colleague to flush out. AI then produced first drafts of the proofs quickly which were then human edited and verified. We suspect that most humans, after looking at Figure 1 , would intuitively understand the transformation from skip list to tree and find it conceivable that a constant balance factor can be maintained at every step of the way; the two appendices confirm this intuition.
In this way we have separated the paper into the entirely human-written body, proofread by AI, and the AI appendix, proofread and edited by humans. The authors feel such a mixed approach where the human-written novel ideas are separated from working out the easily believable but not so interesting is one possible paradigm as we try to work out what papers should look like in this new age.
The figure was also generated interactively with Claude over many rounds; its tikz skills are much better than the authors’.
PopBTree
We now describe the way to interpret a SkipPopList as a multiway search tree. The construction is the standard skip-list to multiway search tree of [21 ] but specialized to our invariants.
Top items. We define the level of an item x x x , written ℓ ( x ) \ell(x) ℓ ( x ) , as the smallest level of the SkipPopList in which x x x is stored. Equivalently, it is the topmost level in the SkipPopList in which x x x resides. We call the items whose top level is exactly ℓ \ell ℓ , the top items of level ℓ \ell ℓ , and write
T o p ℓ = { x ∈ [ n ] : ℓ ( x ) = ℓ } . \mathit{Top}_{\ell} = \{ x \in[n] : \ell(x) = \ell\}. Top ℓ = { x ∈ [ n ] : ℓ ( x ) = ℓ } .
Since every key is stored in ℓ max \ell_{\max} ℓ m a x and each key has a well-defined smallest level, the sets T o p 1 , T o p 2 , … , T o p ℓ max \mathit{Top}_1, \mathit{Top}_2, \ldots, \mathit{Top}_{\ell_{\max}} Top 1 , Top 2 , … , Top ℓ m a x partition [ n ] [n] [ n ] . Moreover, the items stored at level ℓ \ell ℓ are exactly ⋃ ℓ ′ ≤ ℓ T o p ℓ ′ \bigcup_{\ell' \le\ell} \mathit{Top}_{\ell'} ⋃ ℓ ′ ≤ ℓ Top ℓ ′ .
Sentinels and virtual buckets. Throughout, we use two sentinels , 0 0 0 and n + 1 n+1 n + 1 , whose top level we define to be 0 0 0 . They are not stored in the SkipPopList and occupy no real bucket. They are a notational device, made precise as follows. Extend each level ℓ \ell ℓ by two virtual buckets : a bucket − 1 -1 − 1 , permanently occupied by the sentinel 0 0 0 , and a bucket 3 ℓ 3^\ell 3 ℓ , permanently occupied by the sentinel n + 1 n+1 n + 1 . These buckets contain no keys.
Virtual bucket − 1 -1 − 1 of level ℓ \ell ℓ is the rightmost child of virtual bucket − 1 -1 − 1 of level ℓ − 1 \ell-1 ℓ − 1 , consistent with the indexing 3 ⋅ ( − 1 ) + 2 = − 1 3 \cdot(-1) + 2 = -1 3 ⋅ ( − 1 ) + 2 = − 1 , and virtual bucket 3 ℓ 3^\ell 3 ℓ is the leftmost child of virtual bucket 3 ℓ − 1 3^{\ell-1} 3 ℓ − 1 , as 3 ⋅ 3 ℓ − 1 + 0 = 3 ℓ 3 \cdot3^{\ell-1} + 0 = 3^\ell 3 ⋅ 3 ℓ − 1 + 0 = 3 ℓ . Under this convention, the boundary invariants of SkipPopList become instances of the interior. The extreme buckets being vacant says exactly that no occupied bucket, virtual or real, is adjacent to another at the boundary, and Invariant 9 says that between any two consecutive occupied buckets, sentinels included, there are one or two vacant buckets. We may therefore treat sentinel endpoints exactly like stored items in the bucket in the counting arguments below.
The tree T \mathcal{T} T . The tree T \mathcal{T} T , which we call the PopBTree , is a rooted multiway search tree whose keys are the n n n items of [ n ] [n] [ n ] . Each node N N N in the PopBTree is associated with an open key-interval ( a , b ) (a,b) ( a , b ) , its gap . The root’s gap is ( 0 , n + 1 ) (0,n+1) ( 0 , n + 1 ) . If a node has gap ( a ′ , b ′ ) (a',b') ( a ′ , b ′ ) and keys x 1 < ⋯ < x k x_1 < \cdots< x_k x 1 < ⋯ < x k , the gaps of its children are the intervals between consecutive elements of the sequence a ′ , x 1 , … , x k , b ′ a',x_1,\ldots,x_k,b' a ′ , x 1 , … , x k , b ′ . An endpoint of a gap is thus either a key of the parent or inherited from the parent’s own gap. Unwinding the recursion, each of a a a and b b b is a key of some proper ancestor of N N N or a sentinel, and in general the two endpoints belong to two different ancestors. The node N N N with interval ( a , b ) (a,b) ( a , b ) is built as follows:
Among the items lying strictly inside ( a , b ) (a,b) ( a , b ) , let ℓ ∗ \ell^* ℓ ∗ be the smallest top level attained, i.e. the highest level of the SkipPopList reached by any item of ( a , b ) (a,b) ( a , b ) . The keys of N N N are the top items of level ℓ ∗ \ell^* ℓ ∗ that lie in ( a , b ) (a,b) ( a , b ) , listed in increasing order x 1 < x 2 < ⋯ < x k x_1 < x_2 < \cdots< x_k x 1 < x 2 < ⋯ < x k . We say N N N is a node at level ℓ ∗ \ell^* ℓ ∗ .
The keys of N N N split ( a , b ) (a,b) ( a , b ) into the k + 1 k+1 k + 1 subintervals ( a , x 1 ) , ( x 1 , x 2 ) , … , ( x k − 1 , x k ) , ( x k , b ) (a,x_1),(x_1,x_2),\ldots,(x_{k-1},x_k),(x_k,b) ( a , x 1 ) , ( x 1 , x 2 ) , … , ( x k − 1 , x k ) , ( x k , b ) . Each subinterval that contains at least one item is covered by a child node of N N N , defined by the same rule. A subinterval containing no items contributes no child.
The following basic facts about gaps address a subtlety worth stressing: the endpoints of a node’s gap are in general not keys of its parent, so statements about them must be routed through the ancestors that contribute them.
Lemma 27. Gap endpoints. Let N N N be a node of T \mathcal{T} T at level ℓ \ell ℓ with gap ( a , b ) (a,b) ( a , b ) . Then
(i) ℓ ( a ) < ℓ \ell(a)<\ell ℓ ( a ) < ℓ and ℓ ( b ) < ℓ \ell(b)<\ell ℓ ( b ) < ℓ .
(ii) Every item strictly inside ( a , b ) (a,b) ( a , b ) has top level at least ℓ \ell ℓ , and the items of top level exactly ℓ \ell ℓ inside ( a , b ) (a,b) ( a , b ) are precisely the keys of N N N .
(iii) If N N N is not the root, then the level of N N N is strictly greater than the level of its parent. Consequently, levels increase strictly along every root-to-node path, and each endpoint of ( a , b ) (a,b) ( a , b ) has top level at most the level of the parent of N N N .
Proof. We proceed by induction along the path from the root to N N N . For the root, the endpoints of its gap are the sentinels, whose top level is 0. Since every node has positive level, (i) holds. Statement (ii) is exactly the definition of the root’s keys.
Now suppose the claims hold for a node N ′ N' N ′ of level ℓ ′ \ell' ℓ ′ with gap ( a ′ , b ′ ) (a',b') ( a ′ , b ′ ) , and let N N N be the child corresponding to a gap ( a , b ) (a,b) ( a , b ) of N ′ N' N ′ . Each endpoint a a a or b b b is either a key of N ′ N' N ′ or an endpoint of ( a ′ , b ′ ) (a',b') ( a ′ , b ′ ) . In the first case its top level is ℓ ′ \ell' ℓ ′ . In the second case, the induction hypothesis gives top level less than ℓ ′ \ell' ℓ ′ . Thus ℓ ( a ) , ℓ ( b ) ≤ ℓ ′ \ell(a),\ell(b)\leq\ell' ℓ ( a ) , ℓ ( b ) ≤ ℓ ′ .
Next consider any item strictly inside ( a , b ) (a,b) ( a , b ) . Since ( a , b ) ⊆ ( a ′ , b ′ ) (a,b)\subseteq(a',b') ( a , b ) ⊆ ( a ′ , b ′ ) , the induction hypothesis implies that its top level is at least ℓ ′ \ell' ℓ ′ . Moreover, it cannot have top level exactly ℓ ′ \ell' ℓ ′ , because such an item would be a key of N ′ N' N ′ , and the keys of N ′ N' N ′ are not contained strictly inside one of its gaps. Therefore every item inside ( a , b ) (a,b) ( a , b ) has top level at least ℓ ′ + 1 \ell'+1 ℓ ′ + 1 .
By definition, the level of N N N is the minimum top level among the items inside ( a , b ) (a,b) ( a , b ) , hence ℓ ≥ ℓ ′ + 1 \ell\geq\ell'+1 ℓ ≥ ℓ ′ + 1 , this proves (iii). Combining this with ℓ ( a ) , ℓ ( b ) ≤ ℓ ′ \ell(a),\ell(b)\leq\ell' ℓ ( a ) , ℓ ( b ) ≤ ℓ ′ gives ℓ ( a ) , ℓ ( b ) < ℓ \ell(a),\ell(b)<\ell ℓ ( a ) , ℓ ( b ) < ℓ , which is exactly (i). Finally, (ii) follows directly from the definition of the keys of N N N : they are precisely the items inside ( a , b ) (a,b) ( a , b ) whose top level equals the minimum top level ℓ \ell ℓ .
Why this is a search tree
The construction is exactly the branching structure of a B B B -tree. Every node N N N covering ( a , b ) (a,b) ( a , b ) with keys x 1 < ⋯ < x k x_1<\cdots<x_k x 1 < ⋯ < x k has its children living in the gaps ( a , x 1 ) , … , ( x k , b ) (a,x_1),\ldots,(x_k,b) ( a , x 1 ) , … , ( x k , b ) between consecutive keys. The keys of N N N separate the key-ranges of its children in the usual B B B -tree fashion. A search descending into N N N compares the query against x 1 , … , x k x_1,\ldots,x_k x 1 , … , x k and follows the unique gap that contains it. Iterating from the root, every item x x x is a key of exactly one node, the node covering the gap in which x x x attains the highest level. So T \mathcal{T} T stores each of the n n n items exactly once and is a valid search tree over [ n ] [n] [ n ] .
Equivalently, and this is the phrasing we will use, the nodes of T \mathcal{T} T are obtained level by level. At level ℓ \ell ℓ , delete from the items stored at level ℓ \ell ℓ all those already stored at level ℓ − 1 \ell-1 ℓ − 1 . The remaining items are exactly Top ℓ \operatorname{Top}_{\ell} Top ℓ , and each maximal set of them that is consecutive among the items stored at level ℓ \ell ℓ forms one node at level ℓ \ell ℓ .
We now bound the number of keys stored at any node N N N in the PopBTree using the above construction and the invariants of the SkipPopList.
Lemma 28. Node size. Every node of T \mathcal{T} T has at most 4 keys and hence at most 5 children.
Proof. Let N N N be a node at level ℓ \ell ℓ covering the gap ( a , b ) (a,b) ( a , b ) . If N N N is the root, then ℓ = 1 \ell=1 ℓ = 1 . The only non-extreme bucket at level 1 is the middle bucket, so the root has exactly one key. Thus the claim holds. Now suppose N N N is not the root. By Lemma 27 (i), both endpoints of the gap satisfy ℓ ( a ) , ℓ ( b ) < ℓ \ell(a),\ell(b)<\ell ℓ ( a ) , ℓ ( b ) < ℓ . Therefore each endpoint occupies a (possibly virtual) bucket at level ℓ − 1 \ell-1 ℓ − 1 . If the endpoint is a stored item, it appears in the bucket containing its key by the subset property. If it is a sentinel, it occupies its corresponding virtual bucket. These two buckets are consecutive. Indeed, if there were another occupied bucket between them at level ℓ − 1 \ell-1 ℓ − 1 , it would contain an item whose top level is at most ℓ − 1 \ell-1 ℓ − 1 . That item would lie strictly inside ( a , b ) (a,b) ( a , b ) , contradicting Lemma 27 (ii), which states that every item inside ( a , b ) (a,b) ( a , b ) has top level at least ℓ \ell ℓ .
Now, consider the occupied buckets at level ℓ \ell ℓ whose keys lie strictly between a a a and b b b . Their stored items have top level exactly ℓ \ell ℓ , since an item stored at level ℓ − 1 \ell-1 ℓ − 1 would also occupy a bucket between a a a and b b b at level ℓ − 1 \ell-1 ℓ − 1 , contradicting the fact that the endpoint buckets are consecutive. By Lemma 27 (ii), these items are exactly the keys of N N N . It remains to count these buckets.
Spacing at level ℓ − 1 \ell-1 ℓ − 1 : Let a a a occupy bucket p p p and b b b bucket q q q at level ℓ − 1 \ell-1 ℓ − 1 . As a , b a,b a , b are consecutive occupied buckets, no two adjacent buckets are occupied and at most two consecutive buckets are vacant (Invariant 9), so the number of vacant buckets between them is 1 or 2 which gives that q − p ∈ { 2 , 3 } q-p\in\{2,3\} q − p ∈ { 2 , 3 } .
Passing to level ℓ \ell ℓ : Each level-( ℓ − 1 ) (\ell-1) ( ℓ − 1 ) bucket has three children at level ℓ \ell ℓ . Indexing the buckets from 0, bucket p p p has children 3 p , 3 p + 1 , 3 p + 2 3p,3p+1,3p+2 3 p , 3 p + 1 , 3 p + 2 and bucket q q q has children 3 q , 3 q + 1 , 3 q + 2 3q,3q+1,3q+2 3 q , 3 q + 1 , 3 q + 2 . Item a a a occupies the child of p p p that contains its key, some bucket α = 3 p + r a \alpha=3p+r_a α = 3 p + r a with r a ∈ { 0 , 1 , 2 } r_a\in\{0,1,2\} r a ∈ { 0 , 1 , 2 } , and likewise b b b occupies β = 3 q + r b \beta=3q+r_b β = 3 q + r b . (For a sentinel endpoint this holds by the virtual-bucket convention, with r a = 2 r_a=2 r a = 2 for the sentinel 0 and r b = 0 r_b=0 r b = 0 for the sentinel n + 1 n+1 n + 1 .) Every level-ℓ \ell ℓ bucket with index strictly between α \alpha α and β \beta β has all of its keys in ( a , b ) (a,b) ( a , b ) , while buckets α \alpha α and β \beta β themselves hold only a a a and b b b . Hence the keys of N N N occupy buckets in { α + 1 , … , β − 1 } \{\alpha+1,\ldots,\beta-1\} { α + 1 , … , β − 1 } , and
β − α = 3 ( q − p ) + ( r b − r a ) ≤ 3 ⋅ 3 + 2 = 11. \beta-\alpha=3(q-p)+(r_b-r_a)\le3\cdot3+2=11. β − α = 3 ( q − p ) + ( r b − r a ) ≤ 3 ⋅ 3 + 2 = 11.
Counting occupied buckets: Bucket α \alpha α is occupied by a a a , so by the no-two-adjacent-occupied invariant, bucket α + 1 \alpha+1 α + 1 is vacant. Symmetrically β − 1 \beta-1 β − 1 is vacant. Every key of N N N therefore occupies a bucket in [ α + 2 , β − 2 ] [\alpha+2,\beta-2] [ α + 2 , β − 2 ] , a run of β − α − 3 ≤ 8 \beta-\alpha-3\le8 β − α − 3 ≤ 8 consecutive buckets in which no two adjacent buckets may be occupied. This gives at most ⌈ 8 / 2 ⌉ = 4 \lceil8/2\rceil=4 ⌈ 8/2 ⌉ = 4 occupied buckets, so N N N has at most 4 keys and, one child per non-empty gap between consecutive keys giving, at most 5 children.
Next we define the depth of a node in T T T to be the number of nodes on the path from the root to that node, inclusive. Thus the root has depth 1.
Lemma 29. Depth. An item whose top level in the SkipPopList is ℓ \ell ℓ is a key of a node at depth ℓ \ell ℓ in T T T . Equivalently, locating such an item from the root visits exactly ℓ \ell ℓ nodes.
Proof. By construction the keys of a node are top items of a common level, and an item x x x with top level ℓ \ell ℓ is a key of exactly one node which lies at level ℓ \ell ℓ . It therefore suffices to prove that a node at level ℓ \ell ℓ has depth ℓ \ell ℓ , which we do by showing that the transform never skips a level, i.e., the parent of every non-root node at level ℓ \ell ℓ is a node at level ℓ − 1 \ell-1 ℓ − 1 .
Let N N N be a non-root node at level ℓ \ell ℓ covering the gap ( a , b ) (a,b) ( a , b ) , and let N ′ N' N ′ be its parent, a node at level ℓ ′ \ell' ℓ ′ . By Lemma 27 (iii), ℓ ≥ ℓ ′ + 1 \ell\ge\ell'+1 ℓ ≥ ℓ ′ + 1 and ℓ ( a ) , ℓ ( b ) ≤ ℓ ′ \ell(a),\ell(b)\le\ell' ℓ ( a ) , ℓ ( b ) ≤ ℓ ′ , it remains to show ℓ ≤ ℓ ′ + 1 \ell\le\ell'+1 ℓ ≤ ℓ ′ + 1 .
Each of a , b a,b a , b occupies a (possibly virtual) bucket at level ℓ ′ \ell' ℓ ′ , at positions p < q p<q p < q with q ≥ p + 2 q\ge p+2 q ≥ p + 2 , since no two adjacent buckets are occupied. Bucket p + 1 p+1 p + 1 is therefore vacant at level ℓ ′ \ell' ℓ ′ , being adjacent to the occupied bucket p p p , and every key of bucket p + 1 p+1 p + 1 lies strictly between a a a and b b b because it exceeds every key of bucket p p p , hence exceeds a a a , and precedes every key of bucket q q q , hence precedes b b b (if p p p or q q q is virtual the corresponding comparison against the sentinel is trivial). As ℓ ′ < ℓ max \ell' < \ell_{\max} ℓ ′ < ℓ m a x , Lemma 19 applies to bucket p + 1 p+1 p + 1 which has an occupied child at level ℓ ′ + 1 \ell'+1 ℓ ′ + 1 , whose occupant has top level exactly ℓ ′ + 1 \ell'+1 ℓ ′ + 1 and key inside bucket p + 1 p+1 p + 1 , hence inside ( a , b ) (a,b) ( a , b ) . So the smallest top level attained inside ( a , b ) (a,b) ( a , b ) is at most ℓ ′ + 1 \ell'+1 ℓ ′ + 1 , giving ℓ ≤ ℓ ′ + 1 \ell\le\ell'+1 ℓ ≤ ℓ ′ + 1 . Therefore ℓ = ℓ ′ + 1 \ell=\ell'+1 ℓ = ℓ ′ + 1 , i.e. N ′ N' N ′ is at level ℓ − 1 \ell-1 ℓ − 1 .
The claim now follows by induction on ℓ \ell ℓ . The root is the unique node at level 1 and has depth 1. For ℓ ≥ 2 \ell\ge2 ℓ ≥ 2 , a node at level ℓ \ell ℓ has a parent at level ℓ − 1 \ell-1 ℓ − 1 , which has depth ℓ − 1 \ell-1 ℓ − 1 by induction, so the node has depth ℓ \ell ℓ . Hence an item of top level ℓ \ell ℓ , being a key of a level-ℓ \ell ℓ node, sits at depth ℓ \ell ℓ .
In Lemma 28 we bounded the degree of the PopBTree. We now show that in the PopBTree all leaves are at the same depth.
Lemma 30. Uniform depth. Every node of T T T at depth less than ℓ max \ell_{\max} ℓ m a x has at least one child, so every leaf of T T T is at depth ℓ max \ell_{\max} ℓ m a x .
Proof. Let N N N be a node at level ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x , covering ( a , b ) (a,b) ( a , b ) , and let x 1 x_1 x 1 be its leftmost key, an item of top level ℓ \ell ℓ , so x 1 x_1 x 1 occupies a bucket at level ℓ \ell ℓ . To its left within ( a , b ) (a,b) ( a , b ) there is a vacant bucket. Indeed, by Lemma 27 and the subset property, a a a occupies a (possibly virtual) bucket p p p at level ℓ \ell ℓ , and since no two adjacent occupied buckets are permitted, sentinels included, by the virtual-bucket convention, x 1 x_1 x 1 's bucket has index at least p + 2 p+2 p + 2 .
Let c c c be the bucket immediately left of x 1 x_1 x 1 , then c c c is real (its index is at least p + 1 ≥ 0 p+1 \ge0 p + 1 ≥ 0 ), vacant (adjacent to the occupied bucket of x 1 x_1 x 1 ), and its keys exceed a a a and are below x 1 x_1 x 1 , hence lie in ( a , b ) (a,b) ( a , b ) . As ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x , Lemma 19 gives c c c an occupied child at level ℓ + 1 \ell+1 ℓ + 1 , whose key lies in ( a , b ) (a,b) ( a , b ) and has top level ℓ + 1 \ell+1 ℓ + 1 . The node formed in the gap of N N N containing that key is a child of N N N . Hence N N N is not a leaf, and every leaf lies at depth ℓ max \ell_{\max} ℓ m a x .
Together, Lemmas 28 and 30 say that T T T is a B B B -tree because every node has between 1 and 4 keys and at most 5 children, and all root-to-leaf paths have the same length. We use both facts below.
Just as B B [ α ] BB[\alpha] B B [ α ] tree is a BST in which each child's subtree carries at least an α \alpha α fraction of the weight of its parent's subtree, we now give a similar definition for B B B -trees which we call a B B B [ α ] BBB[\alpha] B B B [ α ] tree.
Fix α ∈ ( 0 , 1 2 ] \alpha\in(0,\frac{1}{2}] α ∈ ( 0 , 2 1 ] . For a node v v v of a multiway search tree, let its weight w ( v ) w(v) w ( v ) be one plus the number of keys stored in the subtree rooted at v v v . Equivalently, w ( v ) w(v) w ( v ) is the number of external nodes (empty child slots) of that subtree. When every child slot of a node is nonempty, its external nodes are partitioned among the subtrees of its children, and the weights of the children then sum to the weight of the node. In general (empty slots being external nodes of the parent itself) the children's weights sum to at most the weight of the node.
Definition 31. B B B [ α ] BBB[\alpha] B B B [ α ] tree.
A B B B [ α ] BBB[\alpha] B B B [ α ] tree is a B B B -tree in which every node has a bounded number of children and all leaves lie at the same depth and, for every internal node v v v and every child c c c of v v v ,
w ( c ) ≥ α w ( v ) . w(c) \ge\alpha w(v). w ( c ) ≥ α w ( v ) .
Lemma 32. Subtree size. Let N N N be a node of T T T at level ℓ \ell ℓ , and let s ( N ) s(N) s ( N ) be the number of items stored in the subtree rooted at N N N . Then
n 3 ℓ − 1 ≤ s ( N ) ≤ 4 n 3 ℓ − 1 , \frac{n}{3^{\ell-1}} \le s(N) \le\frac{4n}{3^{\ell-1}}, 3 ℓ − 1 n ≤ s ( N ) ≤ 3 ℓ − 1 4 n , so s ( N ) = Θ ( n / 3 ℓ ) s(N)=\Theta(n/3^\ell) s ( N ) = Θ ( n / 3 ℓ ) , with the two bounds differing by a factor of 4.
Proof. The subtree rooted at N N N stores exactly the data items whose key lies in the interval ( a , b ) (a,b) ( a , b ) that N N N covers. Indeed, every key in ( a , b ) (a,b) ( a , b ) has top level at least ℓ \ell ℓ and is a key of a unique node descended from N N N , while keys outside [ a , b ] [a,b] [ a , b ] lie outside N N N ’s subtree and a , b a,b a , b themselves are keys of ancestors of N N N or sentinels. Hence s ( N ) = b − a − 1 s(N)=b-a-1 s ( N ) = b − a − 1 , the number of integers strictly between a a a and b b b . (For the root, a = 0 a=0 a = 0 and b = n + 1 b=n+1 b = n + 1 , giving s ( N ) = n s(N)=n s ( N ) = n , consistent with the bounds at ℓ = 1 \ell=1 ℓ = 1 .) For a non-root node, a a a and b b b occupy consecutive (possibly virtual) buckets at level ℓ − 1 \ell-1 ℓ − 1 , exactly as in the proof of Lemma 28 , at positions p < q p<q p < q with q − p ∈ { 2 , 3 } q-p\in\{2,3\} q − p ∈ { 2 , 3 } . Each real bucket at level ℓ − 1 \ell-1 ℓ − 1 holds n / 3 ℓ − 1 n/3^{\ell-1} n / 3 ℓ − 1 consecutive keys while virtual buckets hold none. The interval ( a , b ) (a,b) ( a , b ) contains all of the q − p − 1 ≥ 1 q-p-1\ge1 q − p − 1 ≥ 1 full buckets p + 1 , … , q − 1 p+1,\ldots,q-1 p + 1 , … , q − 1 , we have
s ( N ) ≥ ( q − p − 1 ) n 3 ℓ − 1 ≥ n 3 ℓ − 1 . s(N)\ge(q-p-1)\frac{n}{3^{\ell-1}}\ge\frac{n}{3^{\ell-1}}. s ( N ) ≥ ( q − p − 1 ) 3 ℓ − 1 n ≥ 3 ℓ − 1 n .
and ( a , b ) (a,b) ( a , b ) is contained in the union of the key ranges of at most q − p + 1 ≤ 4 q-p+1\le4 q − p + 1 ≤ 4 buckets p , … , q p,\ldots,q p , … , q (virtual buckets among these contribute no keys, so the bound only improves), and we have
s ( N ) ≤ ( q − p + 1 ) n 3 ℓ − 1 ≤ 4 n 3 ℓ − 1 . s(N)\le(q-p+1)\frac{n}{3^{\ell-1}}\le\frac{4n}{3^{\ell-1}}. s ( N ) ≤ ( q − p + 1 ) 3 ℓ − 1 n ≤ 3 ℓ − 1 4 n .
We now use the above lemma to show that the PopBTree is B B B [ α ] BBB[\alpha] B B B [ α ] balanced.
Lemma 33. T \mathcal{T} T is a B B B [ α ] BBB[\alpha] B B B [ α ] tree. T \mathcal{T} T is a B B B [ 1 12 ] BBB[\frac{1}{12}] B B B [ 12 1 ] tree.
Proof. By Lemma 28 every node has at most 5 children, and by Lemma 30 all leaves lie at the common depth ℓ max \ell_{\max} ℓ m a x , so T \mathcal{T} T is a B B B -tree. It remains to check the weight condition of Definition 31 with α = 1 12 \alpha=\frac{1}{12} α = 12 1 .
Let N N N be an internal node at level ℓ \ell ℓ and let c c c be a child of N N N . Since no level is skipped (Lemma 29 ), c c c is at level ℓ + 1 \ell+1 ℓ + 1 . Applying Lemma 32 , the lower bound to s ( c ) s(c) s ( c ) and the upper bound to s ( N ) s(N) s ( N ) , gives
w ( c ) = s ( c ) + 1 ≥ n 3 ℓ + 1 , w ( N ) = s ( N ) + 1 ≤ 4 n 3 ℓ − 1 + 1 = 12 n 3 ℓ + 1. w(c)=s(c)+1\ge\frac{n}{3^\ell}+1,\qquad w(N)=s(N)+1\le\frac{4n}{3^{\ell-1}}+1=\frac{12n}{3^\ell}+1. w ( c ) = s ( c ) + 1 ≥ 3 ℓ n + 1 , w ( N ) = s ( N ) + 1 ≤ 3 ℓ − 1 4 n + 1 = 3 ℓ 12 n + 1.
Writing x = n / 3 ℓ > 0 x=n/3^\ell>0 x = n / 3 ℓ > 0 ,
w ( c ) w ( N ) ≥ x + 1 12 x + 1 ≥ 1 12 . \frac{w(c)}{w(N)}\ge\frac{x+1}{12x+1}\ge\frac{1}{12}. w ( N ) w ( c ) ≥ 12 x + 1 x + 1 ≥ 12 1 .
the last step because 12 ( x + 1 ) = 12 x + 12 ≥ 12 x + 1 12(x+1)=12x+12\ge12x+1 12 ( x + 1 ) = 12 x + 12 ≥ 12 x + 1 . Thus w ( c ) ≥ 1 12 w ( N ) w(c)\ge\frac{1}{12}w(N) w ( c ) ≥ 12 1 w ( N ) for every node N N N and every child c c c , and T \mathcal{T} T satisfies Definition 31 with α = 1 12 \alpha=\frac{1}{12} α = 12 1 .
Weak bounds during restoration. The lemmas so far describe T \mathcal{T} T when all SkipPopList invariants hold between searches. During the restoration that follows a search, the structural invariants are transiently violated, but by Lemma 25 , after every unit-cost operation and at every level ℓ < ℓ max \ell<\ell_{\max} ℓ < ℓ m a x , no two adjacent buckets are occupied, and at most seven consecutive buckets are vacant, and level ℓ max \ell_{\max} ℓ m a x never changes at all (Lemma 18 ). Moreover, the extreme buckets remain vacant at every moment because demotions only vacate buckets, the promotion of x i x_i x i stops below the extreme buckets by definition, and a gap repair fills only the middle of three consecutive vacant buckets. The virtual-bucket convention therefore remains in force. Since the construction of T \mathcal{T} T and Lemma 27 use only the subset property, T \mathcal{T} T is well defined at every instant.
Lemma 34. Weak structural bounds. At every moment during the execution of the restoration method, that is, after every unit-cost operation, the tree T T T read off from the current SkipPopList contents satisfies:
Every level other than level 1 stores at least one item, so the root of T T T is at level 1 or 2.
Every non-root node has at most 12 keys, the root has at most 4 keys, and every node has at most 13 children.
The level of a child exceeds the level of its parent by at most two.
Every node N N N at level ℓ \ell ℓ has subtree size n / 3 ℓ − 1 ≤ s ( N ) ≤ 9 n / 3 ℓ − 1 n/3^{\ell-1} \le s(N) \le9n/3^{\ell-1} n / 3 ℓ − 1 ≤ s ( N ) ≤ 9 n / 3 ℓ − 1 .
Every gap of every node at level ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x contains at least one key, so every non-leaf node has exactly one more child than it has keys.
For every node N N N and every child c c c of N N N , w ( c ) ≥ 1 81 w ( N ) w(c) \ge\frac{1}{81}w(N) w ( c ) ≥ 81 1 w ( N ) .
Proof. (1) A level ℓ ≥ 2 \ell\ge2 ℓ ≥ 2 storing no item would be a run of 3 ℓ ≥ 9 > 7 3^\ell\ge9 > 7 3 ℓ ≥ 9 > 7 consecutive vacant buckets, contradicting Lemma 25 (for ℓ = ℓ max \ell= \ell_{\max} ℓ = ℓ m a x , Lemma 18 ). Hence the smallest top level attained in ( 0 , n + 1 ) (0,n+1) ( 0 , n + 1 ) is 1 or 2.
(2) Repeat the count of Lemma 28 with the weak spacing. The endpoints of a non-root node’s gap occupy consecutive occupied (possibly virtual) buckets at the level above the node. The argument there uses only Lemma 27 and the subset property so the vacant run between them now has length at most 7, hence q − p ≤ 8 q-p \le8 q − p ≤ 8 , giving β − α ≤ 3 ⋅ 8 + 2 = 26 \beta-\alpha\le3\cdot8+2=26 β − α ≤ 3 ⋅ 8 + 2 = 26 and at most ⌈ 23 / 2 ⌉ = 12 \lceil23/2\rceil=12 ⌈ 23/2 ⌉ = 12 occupied buckets in [ α + 2 , β − 2 ] [\alpha+2,\beta-2] [ α + 2 , β − 2 ] .
The root’s keys are the occupied buckets of its level, which is 1 or 2 by (1). Level 1 has one non-extreme bucket and level 2 has seven, of which at most ⌈ 7 / 2 ⌉ = 4 \lceil7/2\rceil=4 ⌈ 7/2 ⌉ = 4 can be occupied, no two being adjacent.
(3) Let ( u , v ) (u,v) ( u , v ) be a nonempty gap of a node N N N at level ℓ \ell ℓ . As in (2), u u u and v v v occupy consecutive occupied buckets at level ℓ \ell ℓ , at positions s < t s<t s < t with t − s ≤ 8 t-s\le8 t − s ≤ 8 , and at level ℓ + 1 \ell+1 ℓ + 1 they occupy buckets σ = 3 s + r u < τ = 3 t + r v \sigma=3s+r_u<\tau=3t+r_v σ = 3 s + r u < τ = 3 t + r v . The τ − σ − 1 ≥ 3 ( t − s ) − 3 ≥ 3 \tau-\sigma-1\ge3(t-s)-3\ge3 τ − σ − 1 ≥ 3 ( t − s ) − 3 ≥ 3 buckets strictly between σ \sigma σ and τ \tau τ have all their keys in ( u , v ) (u,v) ( u , v ) . If one of them is occupied, its occupant lies in ( u , v ) (u,v) ( u , v ) and has top level exactly ℓ + 1 \ell+1 ℓ + 1 because top level at most ℓ \ell ℓ would contradict Lemma 27 (ii). The gap’s node is then at level ℓ + 1 \ell+1 ℓ + 1 . If all are vacant which is impossible when ℓ + 1 = ℓ max \ell+1=\ell_{\max} ℓ + 1 = ℓ m a x , then by Lemma 18 at most two consecutive buckets are vacant, so assume ℓ + 2 ≤ ℓ max \ell+2\le\ell_{\max} ℓ + 2 ≤ ℓ m a x . Then, at least 3 ⋅ 3 = 9 3\cdot3=9 3 ⋅ 3 = 9 children of these buckets are at level ℓ + 2 \ell+2 ℓ + 2 , likewise have all their keys in ( u , v ) (u,v) ( u , v ) , and 9 > 7 9>7 9 > 7 consecutive vacant buckets are forbidden (by Lemma 25 , or by Lemma 18 if ℓ + 2 = ℓ max \ell+2=\ell_{\max} ℓ + 2 = ℓ m a x ), so one of them is occupied. Its occupant has top level exactly ℓ + 2 \ell+2 ℓ + 2 , its parent bucket at level ℓ + 1 \ell+1 ℓ + 1 being vacant. In either case the smallest top level in ( u , v ) (u,v) ( u , v ) is ℓ + 1 \ell+1 ℓ + 1 or ℓ + 2 \ell+2 ℓ + 2 .
(4) Both endpoints of N N N ’s gap have top level below ℓ \ell ℓ (Lemma 27 ) and hence occupy (possibly virtual) buckets at level ℓ − 1 \ell-1 ℓ − 1 directly, whatever the level of N N N ’s parent. As in (2) these are consecutive occupied buckets with q − p ∈ [ 2 , 8 ] q-p\in[2,8] q − p ∈ [ 2 , 8 ] . The interval ( a , b ) (a,b) ( a , b ) contains q − p − 1 ≥ 1 q-p-1\ge1 q − p − 1 ≥ 1 real bucket between them and is contained in the key ranges of q − p + 1 ≤ 9 q-p+1\le9 q − p + 1 ≤ 9 buckets p , … , q p,\ldots,q p , … , q , so n / 3 ℓ − 1 ≤ s ( N ) ≤ 9 n / 3 ℓ − 1 n/3^{\ell-1}\le s(N)\le9n/3^{\ell-1} n / 3 ℓ − 1 ≤ s ( N ) ≤ 9 n / 3 ℓ − 1 .
(5) A gap of a node at level ℓ < ℓ max \ell<\ell_{\max} ℓ < ℓ m a x is delimited by occupants of buckets at level ℓ \ell ℓ at distance at least 2. The real bucket between them holds n / 3 ℓ ≥ 1 n/3^\ell\ge1 n / 3 ℓ ≥ 1 keys (as ℓ ≤ log 3 n \ell\le\log_3 n ℓ ≤ log 3 n ), all strictly inside the gap.
(6) Let c c c be a child of N N N , with N N N at level ℓ \ell ℓ . By (3), c c c is at level ℓ + 1 \ell+1 ℓ + 1 or ℓ + 2 \ell+2 ℓ + 2 , so by (4), w ( c ) = s ( c ) + 1 ≥ n / 3 ℓ + 1 + 1 w(c)=s(c)+1\ge n/3^{\ell+1}+1 w ( c ) = s ( c ) + 1 ≥ n / 3 ℓ + 1 + 1 , while w ( N ) ≤ 9 n / 3 ℓ − 1 + 1 = 27 n / 3 ℓ + 1 w(N)\le9n/3^{\ell-1}+1=27n/3^\ell+1 w ( N ) ≤ 9 n / 3 ℓ − 1 + 1 = 27 n / 3 ℓ + 1 . Writing x = n / 3 ℓ x=n/3^\ell x = n / 3 ℓ ,
81 ( x 3 + 1 ) = 27 x + 81 ≥ 27 x + 1 , 81\left(\frac{x}{3}+1\right)=27x+81\ge27x+1, 81 ( 3 x + 1 ) = 27 x + 81 ≥ 27 x + 1 ,
so w ( c ) ≥ 1 81 w ( N ) w(c)\ge\frac{1}{81}w(N) w ( c ) ≥ 81 1 w ( N ) . □
In particular T \mathcal{T} T satisfies the weight condition of Definition 31 with α = 1 81 \alpha= \frac{1}{81} α = 81 1 at every moment of the execution, not merely between searches. The one property that can fail transiently is uniform leaf depth. By (3) a child may sit two levels below its parent, so the leaves, all of which are at level ℓ max \ell_{\max} ℓ m a x , may transiently lie at depths between ⌈ ℓ max / 2 ⌉ \lceil\ell_{\max}/2 \rceil ⌈ ℓ m a x /2 ⌉ and ℓ max \ell_{\max} ℓ m a x . We return to this point when routing the pointer during restoration.
During the restoration the pointer must visit a scattered set of nodes for the clearing, promotion, and repair of nodes using only parent and child moves. All the nodes lie near the search path in bucket space, and we show that the subtree connecting them to the root has total size O ( ℓ i ( x i ) ) O(\ell_i(x_i)) O ( ℓ i ( x i )) . A depth-first traversal of the nodes then visits every node cheaply. Crucially, the size bound rests only on the weak structural bounds of Lemma 34 , so it holds at every moment of the restoration.
Lemma 35. Connecting subtree. Let c ≥ 2 c \ge2 c ≥ 2 be a constant. Fix a search x i x_i x i , let ℓ i = ℓ i ( x i ) \ell_i = \ell_i(x_i) ℓ i = ℓ i ( x i ) be its maximum level at the start of the search, and for each level λ \lambda λ let B λ B_\lambda B λ be the bucket containing the key x i x_i x i at level λ \lambda λ . Let the window W λ W_\lambda W λ be the union of the key ranges of the buckets at distance at most c c c from B λ B_\lambda B λ . At any moment during the search or its restoration, let T S T_S T S consist of the root together with every node whose level λ \lambda λ satisfies λ ≤ ℓ i + 2 \lambda\le\ell_i + 2 λ ≤ ℓ i + 2 and whose gap intersects W λ W_\lambda W λ . Then T S T_S T S is a subtree of T \mathcal{T} T containing the root, with O ( 1 ) O(1) O ( 1 ) nodes at each level and ∣ T S ∣ = O ( ℓ i ) |T_S| = O(\ell_i) ∣ T S ∣ = O ( ℓ i ) in total.
Proof. Bucket B λ − 1 B_{\lambda-1} B λ − 1 is the parent of B λ B_\lambda B λ , and each level-( λ − 1 ) (\lambda- 1) ( λ − 1 ) bucket spans three level-λ \lambda λ buckets, so the buckets at distance at most c c c from B λ B_\lambda B λ are contained in the buckets at distance at most ⌈ ( c + 2 ) / 3 ⌉ ≤ c \lceil(c + 2)/3\rceil\le c ⌈( c + 2 ) /3 ⌉ ≤ c from B λ − 1 B_{\lambda-1} B λ − 1 (using c ≥ 2 c \ge2 c ≥ 2 ), hence W λ ⊆ W λ − 1 W_\lambda\subseteq W_{\lambda-1} W λ ⊆ W λ − 1 .
Now, let N ∈ T S N \in T_S N ∈ T S be a non-root node at level λ \lambda λ with parent N ′ N' N ′ at level λ ′ < λ \lambda' < \lambda λ ′ < λ . The gap of N ′ N' N ′ contains the gap of N N N , which intersects W λ ⊆ W λ ′ W_\lambda\subseteq W_{\lambda'} W λ ⊆ W λ ′ , so N ′ ∈ T S N' \in T_S N ′ ∈ T S . Being closed under taking parents and containing the root, T S T_S T S is a subtree.
Finally, distinct nodes at level λ \lambda λ have disjoint gaps, and by Lemma 34 (4), which holds at every moment and each such gap contains at least n / 3 λ − 1 n/3^{\lambda-1} n / 3 λ − 1 keys, i.e. spans at least three level-λ \lambda λ bucket lengths in key space. The window W λ W_\lambda W λ spans 2 c + 1 2c+1 2 c + 1 bucket lengths, so at most ( 2 c + 1 ) / 3 + 2 = O ( 1 ) (2c+1)/3+2 = O(1) ( 2 c + 1 ) /3 + 2 = O ( 1 ) gaps of level-λ \lambda λ nodes can intersect it. Summing over at most ℓ i + 2 \ell_i+2 ℓ i + 2 levels gives ∣ T S ∣ = O ( ℓ i ) |T_S| = O(\ell_i) ∣ T S ∣ = O ( ℓ i ) .
A depth-first traversal of T S T_S T S from the root, descending only into children that belong to T S T_S T S , moves the pointer along each edge of T S T_S T S at most twice and hence visits every node of T S T_S T S in O ( ℓ i ) O(\ell_i) O ( ℓ i ) pointer moves, only unit-cost operations, not computation. The bound holds when the traversal is interleaved with edits , the constant-size updates of T \mathcal{T} T defined before Lemma 36 below, provided each edit modifies only the pointer’s current node, its children, or its ancestors on the current traversal stack, and replaces O ( 1 ) O(1) O ( 1 ) nodes by O ( 1 ) O(1) O ( 1 ) nodes whose gaps lie in the same windows. The traversal simply continues on the current tree. Over the whole restoration only O ( ℓ i ) O(\ell_i) O ( ℓ i ) nodes ever belong to T S T_S T S (O ( ℓ i ) O(\ell_i) O ( ℓ i ) initially, plus O ( 1 ) O(1) O ( 1 ) per promotion or demotion), so the total number of pointer moves remains O ( ℓ i ) O(\ell_i) O ( ℓ i ) .
We maintain T \mathcal{T} T so that it always mirrors the current SkipPopList. This means that the keys of the level-ℓ \ell ℓ nodes are exactly the top items of level ℓ \ell ℓ . A single promotion or demotion of the model changes the top level of one item by one, and we show that the matching update of T \mathcal{T} T can be implemented by rewriting the keys and child pointers of O ( 1 ) O(1) O ( 1 ) nodes, all within one pointer hop of the pointer; we call such a constant-size update an edit .
Lemma 36. Constant-time promotion and demotion. Suppose that, at any moment during a search or its restoration, the pointer rests on the node N N N of T \mathcal{T} T that stores an item x x x as a key, the node at x x x ’s current top level. Then the promotion or demotion of x x x , as defined in the skip-list cost model, can be mirrored in T \mathcal{T} T in O ( 1 ) O(1) O ( 1 ) time, touching only nodes within one pointer hop of N N N .
Proof. Let x x x have top level ℓ \ell ℓ . Every node mentioned below has O ( 1 ) O(1) O ( 1 ) keys and children by Lemma 34(2), which holds at every moment of the restoration. We do not assume the full invariants.
Demotion: (ℓ → ℓ + 1 \ell\to\ell+ 1 ℓ → ℓ + 1 ; possible only for ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x ). Within N N N , the key x x x is flanked by the two gaps ( u , x ) (u,x) ( u , x ) and ( x , v ) (x,v) ( x , v ) , where u u u and v v v are the keys of N N N neighboring x x x or, if x x x is the leftmost or rightmost key, the corresponding endpoint of N N N ’s gap (possibly a sentinel). Removing x x x from level ℓ \ell ℓ merges these two gaps into the single gap ( u , v ) (u,v) ( u , v ) . Its node is a new node c c c . Since x x x is stored at level ℓ + 1 \ell+ 1 ℓ + 1 by the subset property now has top level ℓ + 1 \ell+ 1 ℓ + 1 , and no other item of ( u , v ) (u,v) ( u , v ) has top level below ℓ + 1 \ell+ 1 ℓ + 1 . So node c c c is at level ℓ + 1 \ell+ 1 ℓ + 1 and has x x x among its keys. Concretely, c c c is assembled from O ( 1 ) O(1) O ( 1 ) existing pieces.
The child of N N N in the gap ( u , x ) (u,x) ( u , x ) exists, the gap containing at least one item by Lemma 34(5), as ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x . If that child is at level ℓ + 1 \ell+ 1 ℓ + 1 , its keys and child subtrees form the portion of c c c left of x x x . If it is at level ℓ + 2 \ell+ 2 ℓ + 2 (a transient level skip, Lemma 34(3)), it instead becomes the child of c c c hanging in the gap immediately left of x x x . Symmetrically on the right. Finally x x x is deleted from N N N . If x x x was the only key of N N N , then N N N ceases to exist and c c c takes N N N ’s place as a child of N N N ’s parent. If N N N was the root, c c c becomes the root, consistent with Lemma 34(1). In every case a constant number of nodes, each within one pointer hop of N N N , are read and rewritten. Moving the pointer down onto c c c finishes the operation, matching the cost model, in which a demotion moves the pointer down one level.
Promotion: (ℓ → ℓ − 1 \ell\to\ell- 1 ℓ → ℓ − 1 ; possible only for ℓ > 1 \ell> 1 ℓ > 1 , and performed by the maintenance method only after the destination bucket and its neighbors have been cleared). Here M : = N M := N M := N stores x x x at level ℓ \ell ℓ . Inserting x x x into the level above turns x x x into a delimiter, splitting M M M at x x x . The keys of M M M left of x x x , with their child subtrees, form M L M_L M L , and those right of x x x form M R M_R M R . If M L M_L M L (respectively M R M_R M R ) has no keys, it is not a node, and its place is taken directly by the leftmost (rightmost) child subtree of M M M , one level further down, or by nothing if that side of M M M ’s gap holds no items. If M M M is the root, it has no parent, and the promotion is into level 1. Note that the root not being at level 1 forces it to be at level 2 with level 1 empty (Lemma 34(1)). So after the promotion, x x x is the unique item of top level 1, and x x x becomes the new root, a single-key node at level 1 with M L M_L M L and M R M_R M R as its children. Only M M M and the O ( 1 ) O(1) O ( 1 ) pointers among its pieces are touched.
Otherwise, let N ′ N' N ′ be the parent of M M M . What happens above then depends on the level of N ′ N' N ′ . If N ′ N' N ′ is at level ℓ − 1 \ell- 1 ℓ − 1 , then x x x , with new top level ℓ − 1 \ell- 1 ℓ − 1 , lies strictly inside N ′ N' N ′ ’s gap and becomes a key of N ′ N' N ′ . The child slot held by M M M is replaced by the key x x x flanked by two slots holding M L M_L M L and M R M_R M R . If instead N ′ N' N ′ is at level ℓ − 2 \ell- 2 ℓ − 2 (a transient skip, as arises during gap repair), then x x x becomes a new single-key node at level ℓ − 1 \ell- 1 ℓ − 1 occupying M M M ’s slot as a child of N ′ N' N ′ , with M L M_L M L and M R M_R M R as its children. Only M M M , N ′ N' N ′ , and the O ( 1 ) O(1) O ( 1 ) pointers between them are touched. Moving the pointer up onto the node now containing x x x finishes the operation, matching the cost model.
In both directions a constant number of nodes, each of constant size, are split or merged, and only a constant number of keys and child pointers are rewritten, all within one pointer hop of where the pointer began. Hence each operation runs in O ( 1 ) O(1) O ( 1 ) time.
That the nodes stay of constant size throughout a maintenance pass is not a bookkeeping accident but an instance of Lemma 34(2): after every unit-cost operation every node has at most 12 keys, and the bound of 4 from Lemma 28 is restored together with the invariants.
Next, to run the maintenance with a pointer that cannot move between siblings, we need to know that all its operation sites lie in the connecting subtree.
Lemma 37. Locality. There is an absolute constant c 0 c_0 c 0 such that, for every search, every unit-cost operation of the restoration method acts on an item whose bucket, at the level of the operation,
is within distance c 0 c_0 c 0 of the bucket containing the searched key at that level, and every operation takes place at a level at most ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) . Consequently, at every moment, every node of T T T at which an operation must be performed, and every node created, destroyed, or modified, belongs to the connecting subtree T S T_S T S of Lemma 35 with constant c = max ( c 0 , 2 ) c=\max(c_0,2) c = max ( c 0 , 2 ) .
Proof. First the buckets, read off the maintenance method. A clearing cascade demotes an item y y y that occupies, at some level λ < ℓ i ( x i ) \lambda< \ell_i(x_i) λ < ℓ i ( x i ) , the bucket containing x i x_i x i or a bucket adjacent to it. The cascade acts at the levels from y y y ’s top level down to λ \lambda λ . At any such level λ ′ \lambda' λ ′ , the bucket of y y y is an ancestor of its bucket at level λ \lambda λ , and since ancestors of adjacent buckets are equal or adjacent, the bucket of y y y at level λ ′ \lambda' λ ′ is within distance one of the bucket of x i x_i x i ’s key there. The promotion of x i x_i x i acts on the buckets containing x i x_i x i itself—distance zero. A gap repair fills the middle of three consecutive vacant buckets, at least one of which was vacated by a demotion and is therefore within one of x i x_i x i ’s bucket, so the filled bucket is within four of x i x_i x i ’s bucket. The item promoted into it comes from a child of the filled bucket, within 3 ⋅ 4 + 2 = 14 3\cdot4+2=14 3 ⋅ 4 + 2 = 14 of x i x_i x i ’s bucket one level down. Taking c 0 = 14 c_0=14 c 0 = 14 covers every case.
Now pass to T T T . An operation on an item whose bucket is within c 0 c_0 c 0 of B λ B_\lambda B λ is performed, per Lemma 36, at the node holding that item as a key. That node’s gap contains the item’s key and hence intersects the window W λ W_\lambda W λ , so the node is in T S T_S T S (its level is at most ℓ i + 1 ≤ ℓ i + 2 \ell_i+1\le\ell_i+2 ℓ i + 1 ≤ ℓ i + 2 ). The O ( 1 ) O(1) O ( 1 ) nodes rewritten by the operation, the node itself, its parent, and the replacements assembled from its children, have gaps meeting the window at their own levels, all at most ℓ i + 2 \ell_i+2 ℓ i + 2 , and so also lie in T S T_S T S . □ \square □
The algorithm may start from any SkipPopList satisfying the invariants; the initial PopBTree, and as we later describe the PopTree, are read off from it.
Theorem 38. PopBTree. There is an online algorithm that maintains the PopBTree T T T over [ n ] [n] [ n ] , using a single pointer that moves only from a node to its parent or to one of its children, such that: after every search T T T is a B B B [ 1 12 ] \mathrm{BBB}[\frac{1}{12}] BBB [ 12 1 ] tree, after every unit-cost operation T T T satisfies the weight condition of Definition 31 with α = 1 81 \alpha=\frac{1}{81} α = 81 1 , and any search sequence X X X of length Ω ( n log n ) \Omega(n\log n) Ω ( n log n ) is processed in total time O ( OPT ( X ) ) O(\operatorname{OPT}(X)) O ( OPT ( X )) .
Proof. The algorithm keeps T T T equal to the tree of the current SkipPopList, by Lemma 33 this is a B B B [ 1 12 ] \mathrm{BBB}[\frac{1}{12}] BBB [ 12 1 ] tree between searches. Consider the i i i th search, for x i x_i x i , and let ℓ i = ℓ ( x i ) \ell_i=\ell(x_i) ℓ i = ℓ ( x i ) be its top level just before the search. We bound the work on this search by O ( ℓ i ) O(\ell_i) O ( ℓ i ) .
Search. Starting at the root, repeatedly compare x i x_i x i against the O ( 1 ) O(1) O ( 1 ) keys of the current node and descend into the child whose interval contains x i x_i x i , until x i x_i x i is found. By Lemma 29 the node storing x i x_i x i sits at depth ℓ i \ell_i ℓ i , so this is ℓ i \ell_i ℓ i parent-to-child moves with O ( 1 ) O(1) O ( 1 ) work each, i.e. O ( ℓ i ) O(\ell_i) O ( ℓ i ) time, and uses no sibling moves.
Restoration. The algorithm then mirrors in T T T the SkipPopList maintenance that reinstates the invariants after searching x i x_i x i . That maintenance performs O ( ℓ i ) O(\ell_i) O ( ℓ i ) promotions and demotions in the prescribed order, clearing demotions, then the promotion of x i x_i x i , then gap repairs, as tallied in the proof of Lemma 24. By Lemma 37, every operation site lies at every moment in the connecting subtree T S T_S T S of Lemma 35. The pointer is routed in three passes, one per phase, respecting the order of the method.
Clearing pass. A depth-first traversal of T S T_S T S . Whenever the pointer reaches a node holding an item y y y that must be cleared, with the node’s level being y y y ’s top level, it executes y y y ’s entire cascade: each demotion is an O ( 1 ) O(1) O ( 1 ) -time edit at the pointer (Lemma 36) that drops the pointer one level, onto the node into which y y y was merged, precisely where the next demotion of y y y takes place, since a demotion is permitted only at an item’s top level. When the cascade ends the pointer climbs back up and resumes the traversal. The climb is paid for by the cascade’s own operations. Because the traversal visits a node before its descendants, and merges performed by demotions only combine nodes below the pointer, every cascade top is reached and every cascade runs top-down as the model requires.
Promotion pass. The pointer returns to the root and descends to the node holding x i x_i x i , of depth at most its level ℓ i \ell_i ℓ i (Lemma 34(3)), then promotes x i x_i x i one level at a time, the pointer riding up with each promotion (Lemma 36), until the bucket above is extreme or level 1 is reached.
Repair pass. A second depth-first traversal of T S T_S T S . At each repair site the pointer stands on the node, one level below the vacancy, holding the item to be promoted, and performs the promotion in O ( 1 ) O(1) O ( 1 ) time (Lemma 36). The edit touches only the pointer’s node and its parent, which is on the traversal stack. Repairs do not cascade, as a promotion vacates nothing.
Each pass moves the pointer O ( ℓ i ) O(\ell_i) O ( ℓ i ) times: the two traversals run over a subtree that has O ( ℓ i ) O(\ell_i) O ( ℓ i ) nodes at every moment (Lemma 35) and is edited only at the pointer, its children, and its stacked ancestors (Lemma 36), and the promotion pass is a single descent and ascent. Hence the restoration costs O ( ℓ i ) O(\ell_i) O ( ℓ i ) . Once it finishes the invariants hold (Lemma 23), so by Lemma 33 T T T is again a B B B [ 1 / 12 ] BBB^{[1/12]} B B B [ 1/12 ] tree, and after every intermediate unit-cost operation T T T satisfies the weight condition with α = 1 81 \alpha= \frac{1}{81} α = 81 1 , by Lemma 34(6).
Summing, the algorithm spends O ( ∑ i ℓ i ( x i ) ) O(\sum_i \ell_i(x_i)) O ( ∑ i ℓ i ( x i )) time, which by Corollary 22 is O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) whenever ∣ X ∣ = Ω ( n log n ) |X| = \Omega(n \log n) ∣ X ∣ = Ω ( n log n ) .
PopTree
The PopBTree described in the previous subsection, although it achieves optimal cost for any search sequence X X X , is not a BST. In this section we describe how we turn it into a binary search tree, the PopTree , that for any search sequence X X X has cost O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) .
To convert the PopBTree into PopTree, we expand each PopBTree node into a right-leaning chain, and show four things:
The expansion preserves depth up to a constant factor.
Each unit of PopBTree work becomes O ( 1 ) O(1) O ( 1 ) unit-cost operations of the BST model, i.e., moving a single pointer to the parent, left child, or right child, and single rotations of the pointed node with its parent.
The PopTree is a B B [ 1 / 20 ] BB^{[1/20]} B B [ 1/20 ] tree whenever the SkipPopList invariants hold.
The PopTree is a B B [ α 1 ] BB[\alpha_1] B B [ α 1 ] tree, for an absolute constant α 1 > 0 \alpha_1 > 0 α 1 > 0 , after every unit-cost operation.
The right-chain expansion. Let N N N be a PopBTree node with keys k 1 < k 2 < ⋯ < k m k_1 < k_2 < \cdots< k_m k 1 < k 2 < ⋯ < k m (so 1 ≤ m ≤ 4 1 \le m \le4 1 ≤ m ≤ 4 by Lemma 28) and child subtrees c 0 , c 1 , … , c m c_0,c_1,\ldots,c_m c 0 , c 1 , … , c m , where c t c_t c t holds the keys between k t k_t k t and k t + 1 k_{t+1} k t + 1 , with c 0 c_0 c 0 the keys below k 1 k_1 k 1 and c m c_m c m those above k m k_m k m . Replace N N N by the right chain on its keys: k 1 k_1 k 1 at the top, and k t + 1 k_{t+1} k t + 1 the right child of k t k_t k t for 1 ≤ t < m 1 \le t < m 1 ≤ t < m . Hang the (recursively converted) child subtrees on this chain by making c t − 1 c_{t-1} c t − 1 the left child of k t k_t k t for 1 ≤ t ≤ m 1 \le t \le m 1 ≤ t ≤ m , and c m c_m c m the right child of k m k_m k m . The result is a binary search tree on the keys of N N N and its children: from k t k_t k t the right subtree holds keys larger than k t k_t k t and the left subtree holds the interval ( k t − 1 , k t ) (k_{t-1}, k_t) ( k t − 1 , k t ) . Applying this expansion at every node turns the PopBTree T T T into a binary search tree, the PopTree , denoted as P \mathcal{P} P (see Figure 1).
Lemma 39. Depth is preserved. An item at level ℓ \ell ℓ of the PopBTree lies at depth between ℓ \ell ℓ and 4 ℓ 4\ell 4 ℓ in the PopTree. In particular an item at PopBTree depth ℓ i ( x i ) \ell_i(x_i) ℓ i ( x i ) is at PopTree depth Θ ( ℓ i ( x i ) ) \Theta(\ell_i(x_i)) Θ ( ℓ i ( x i )) .
Proof. The root-to-item path in P \mathcal{P} P passes through the chains of the ℓ \ell ℓ PopBTree nodes on the item’s root-to-node path. It enters each chain at its top and walks down at most m ≤ 4 m \le4 m ≤ 4 chain nodes before stepping into a child (or reaching the item), so its length is at most 4 ℓ 4\ell 4 ℓ and at least ℓ \ell ℓ , one node per chain.
Lemma 40. Constant-time simulation by rotations. Each unit-cost P o p B T r e e PopBTree P o pB T r ee operation, is realized on the P o p T r e e PopTree P o pT r ee by O ( 1 ) O(1) O ( 1 ) unit-cost operations of the B S T BST B S T model. The P o p T r e e PopTree P o pT r ee after the O ( 1 ) O(1) O ( 1 ) unit-cost operations is exactly the right-chain expansion of the updated P o p B T r e e PopBTree P o pB T r ee .
Proof. Pointer moves: Each P o p B T r e e PopBTree P o pB T r ee node is a chain of O ( 1 ) O(1) O ( 1 ) P o p T r e e PopTree P o pT r ee nodes, at every moment ((Lemma 34(2))). To move to a child of N N N , descend within N N N ’s chain to the relevant key and step to its left or right child. To move to the parent of N N N , ascend to the top of N N N ’s chain and take one step further, both O ( 1 ) O(1) O ( 1 ) moves, and no rotations.
Promotion: Let x = k j x = k_j x = k j be a key of the chain of M M M , whose keys are k 1 < ⋯ < k m k_1 < \cdots< k_m k 1 < ⋯ < k m with child subtrees c 0 , … , c m c_0,\ldots,c_m c 0 , … , c m , and let the pointer rest on x x x . Rotate x x x with its parent, j − 1 j-1 j − 1 times. We claim that afterwards x x x occupies the position where the top of M M M ’s chain stood, with left subtree exactly the expansion of M L M_L M L (the keys k 1 , … , k j − 1 k_1,\ldots,k_{j-1} k 1 , … , k j − 1 with children c 0 , … , c j − 1 c_0,\ldots,c_{j-1} c 0 , … , c j − 1 ) and right subtree exactly the expansion of M R M_R M R (the keys k j + 1 , … , k m k_{j+1},\ldots,k_m k j + 1 , … , k m with children c j , … , c m c_j,\ldots,c_m c j , … , c m ). The right subtree of x x x is the chain k j + 1 , … , k m k_{j+1},\ldots,k_m k j + 1 , … , k m and is never touched. For the left, induct on the rotations: when x x x is rotated above k t k_t k t (for t = j − 1 , … , 1 t=j-1,\ldots,1 t = j − 1 , … , 1 ), the node k t k_t k t becomes the left child of x x x , keeps its left subtree exp ( c t − 1 ) \exp(c_{t-1}) exp ( c t − 1 ) , and receives as right subtree the previous left subtree of x x x , which by induction is the expansion of the block k t + 1 , … , k j − 1 k_{t+1},\ldots,k_{j-1} k t + 1 , … , k j − 1 with children c t , … , c j − 1 c_t,\ldots,c_{j-1} c t , … , c j − 1 . This results in the expansion of the block k t , … , k j − 1 k_t,\ldots,k_{j-1} k t , … , k j − 1 with children c t − 1 , … , c j − 1 c_{t-1},\ldots,c_{j-1} c t − 1 , … , c j − 1 . At t = 1 t=1 t = 1 this is exp ( M L ) \exp(M_L) exp ( M L ) .
It remains to move x x x one level up. If M M M hung as the left child of a chain node v v v of its parent’s chain, one further rotation of x x x with v v v makes x x x the predecessor of v v v in that chain, with left subtree exp ( M L ) \exp(M_L) exp ( M L ) , while v v v receives exp ( M R ) \exp(M_R) exp ( M R ) as its left subtree. This is exactly the expansion of the P o p B T r e e PopBTree P o pB T r ee after the promotion, in which x x x is inserted as a key before v v v with M L , M R M_L,M_R M L , M R in the two flanking slots. If M M M hung as the right child of the last chain node u u u of its parent’s chain, no further rotation is needed as x x x is already the right child of u u u and extending the chain by the key x x x with subtrees exp ( M L ) , exp ( M R ) \exp(M_L),\exp(M_R) exp ( M L ) , exp ( M R ) gives the correct expansion. In total at most m ≤ O ( 1 ) m \le O(1) m ≤ O ( 1 ) rotations, each of the pointed node with its parent, with the pointer riding on x x x throughout. The degenerate cases of Lemma 36 when M L M_L M L or M R M_R M R empty, the promotion creating a new single-key node one level up during a transient skip, or M M M being the root, this correspond to shorter instances of the same rotation trace. In the root case no further rotation is needed, as x x x already stands at the root position after the j − 1 j-1 j − 1 rotations, with subtrees exp ( M L ) \exp(M_L) exp ( M L ) and exp ( M R ) \exp(M_R) exp ( M R ) .
Demotion: This is the inverse rotation sequence. The pointer rests on x x x , a chain node whose P o p B T r e e PopBTree P o pB T r ee demotion merges the two blocks flanking x x x . Repeatedly, the pointer steps to the child of x x x that must rise, the top of the offending block’s chain and rotates it up, then steps back to x x x . Each such iteration is one child move, one rotation, and one move back, and undoes one step of the promotion trace read backwards. After O ( 1 ) O(1) O ( 1 ) iterations the tree is the expansion of the P o p B T r e e PopBTree P o pB T r ee after the demotion, and the pointer stands on x x x , now a chain node of the merged node one level down, matching the cost model. If the demotion removes the last key of x x x ’s old node, nothing special occurs in the P o p T r e e PopTree P o pT r ee because there are no empty chains, only the absence of one, and the merged chain hangs where the old chain hung.
We next show that the P o p T r e e PopTree P o pT r ee is a B B [ α ] BB[\alpha] B B [ α ] tree.
Lemma 41. The PopTree is B B [ α ] BB[\alpha] B B [ α ] . The P o p T r e e PopTree P o pT r ee P \mathcal{P} P is a B B [ 1 20 ] BB[\frac{1}{20}] B B [ 20 1 ] tree.
Proof. Give each node u u u of P \mathcal{P} P the weight w ( u ) w(u) w ( u ) . We show that each child subtree of u u u has weight at least 1 20 w ( u ) \frac{1}{20}w(u) 20 1 w ( u ) , which is the B B [ 1 20 ] BB[\frac{1}{20}] B B [ 20 1 ] condition.
Let u = k j u = k_j u = k j be a PopTree node lying in the chain of a PopBTree node N N N at level ℓ \ell ℓ , with keys k 1 , … , k m k_1,\ldots,k_m k 1 , … , k m and children c 0 , … , c m c_0,\ldots,c_m c 0 , … , c m . The subtree of u u u consists of the keys k j , … , k m k_j,\ldots,k_m k j , … , k m together with the child subtrees c j − 1 , … , c m c_{j-1},\ldots,c_m c j − 1 , … , c m , whose external nodes are disjoint, so w ( u ) = ∑ t = j − 1 m w ( c t ) w(u) = \sum_{t=j-1}^{m} w(c_t) w ( u ) = ∑ t = j − 1 m w ( c t ) , a sum of m − j + 2 ≤ 5 m-j+2 \le5 m − j + 2 ≤ 5 terms. The left child subtree of u u u is the converted c j − 1 c_{j-1} c j − 1 , of weight w ( c j − 1 ) w(c_{j-1}) w ( c j − 1 ) , and the right child subtree is k j + 1 , … , k m k_{j+1},\ldots,k_m k j + 1 , … , k m with c j , … , c m c_j,\ldots,c_m c j , … , c m when j < m j < m j < m (weight ∑ t = j m w ( c t ) \sum_{t=j}^{m} w(c_t) ∑ t = j m w ( c t ) ), and the converted c m c_m c m when j = m j = m j = m .
Internal node N N N (ℓ < ℓ max \ell< \ell_{\max} ℓ < ℓ m a x ): Every gap of an internal node has a nonempty child. Its two delimiters occupy consecutive occupied buckets at level ℓ \ell ℓ , sentinels included, by the virtual-bucket convention, which covers the outer gaps of the root and the leftmost and rightmost nodes, and are separated by a vacant bucket, which by Lemma 19 has an occupied child one level down whose occupant lies in the gap. Hence all c 0 , … , c m c_0,\ldots,c_m c 0 , … , c m are nonempty, each a level-( ℓ + 1 ) (\ell+1) ( ℓ + 1 ) subtree (Lemma 29), so by Lemma 32,
S + 1 ≤ w ( c t ) ≤ 4 S + 1 , S : = n 3 ℓ ≥ 1. S + 1 \le w(c_t) \le4S + 1,\qquad S := \frac{n}{3^\ell} \ge1. S + 1 ≤ w ( c t ) ≤ 4 S + 1 , S := 3 ℓ n ≥ 1.
Then w ( u ) ≤ ( m − j + 2 ) ( 4 S + 1 ) ≤ 5 ( 4 S + 1 ) = 20 S + 5 w(u) \le(m-j+2)(4S+1) \le5(4S+1) = 20S+5 w ( u ) ≤ ( m − j + 2 ) ( 4 S + 1 ) ≤ 5 ( 4 S + 1 ) = 20 S + 5 , while each child subtree contains at least one c t c_t c t and so has weight at least S + 1 S+1 S + 1 . Therefore each child subtree has weight ratio
S + 1 20 S + 5 ≥ 1 20 . \frac{S+1}{20S+5} \ge\frac{1}{20}. 20 S + 5 S + 1 ≥ 20 1 .
Leaf node N N N (ℓ = ℓ max \ell= \ell_{\max} ℓ = ℓ m a x ). Here u u u ’s subtree contains only the ≤ 4 \le4 ≤ 4 keys k j , … , k m k_j,\ldots,k_m k j , … , k m , so w ( u ) ≤ 5 w(u) \le5 w ( u ) ≤ 5 , while every child subtree has weight at least 1 so 1 ≥ 1 20 ⋅ 5 1 \ge\frac{1}{20}\cdot5 1 ≥ 20 1 ⋅ 5 , so the condition holds here too. Thus every node of P P P has both child subtrees of weight at least 1 20 w ( u ) \frac{1}{20}w(u) 20 1 w ( u ) , so P P P is a B B [ 1 20 ] BB[\frac{1}{20}] B B [ 20 1 ] tree.
In a binary tree the weights of the two children of a node sum to the weight of the node, where missing children are counted with weight one. Hence the lower bound w ( child ) ≥ α w ( u ) w(\text{child}) \ge\alpha w(u) w ( child ) ≥ α w ( u ) for both children implies the upper bound w ( child ) ≤ ( 1 − α ) w ( u ) w(\text{child}) \le(1-\alpha)w(u) w ( child ) ≤ ( 1 − α ) w ( u ) . Thus Lemma 41 says precisely that the PopTree satisfies Definition 1 with α = 1 20 \alpha= \frac{1}{20} α = 20 1 and β = 19 20 \beta= \frac{19}{20} β = 20 19 .
Lemma 42. Balance at every step. There is an absolute constant α 1 > 0 \alpha_1 > 0 α 1 > 0 , our crude accounting gives α 1 = 1 729 \alpha_1 = \frac{1}{729} α 1 = 729 1 , such that after every unit-cost operation of the PopTree algorithm, including every single rotation inside the rotation sequences of Lemma 40, the PopTree is a B B [ α 1 ] BB[\alpha_1] B B [ α 1 ] tree.
Proof. Pointer moves do not change the tree, so it suffices to consider the trees occurring between consecutive rotations. By Lemma 40 each such tree is the right-chain expansion of the current PopBTree in which at most one O ( 1 ) O(1) O ( 1 ) -size region is part-way through an edit, and by the inductive description in that proof, every BST node of the region is a chain node of a block.
Let u u u be any BST node at such a moment, a chain node of a block of a PopBTree node at some level ℓ \ell ℓ , and write x = n / 3 ℓ x = n/3^\ell x = n / 3 ℓ . The subtree of u u u is contained in the subtree of the topmost PopBTree node involved, whose level is at least ℓ − 2 \ell-2 ℓ − 2 (an edit spans at most the levels ℓ − 2 , … , ℓ + 2 \ell-2,\ldots,\ell+2 ℓ − 2 , … , ℓ + 2 , by Lemma 34(3) and the descriptions in Lemma 36), so by Lemma 34(4),
w ( u ) ≤ 9 n 3 ℓ − 3 + 1 = 243 x + 1. w(u) \le\frac{9n}{3^{\ell-3}} + 1 = 243x + 1. w ( u ) ≤ 3 ℓ − 3 9 n + 1 = 243 x + 1.
Each of the two subtrees of u u u either contains a full child subtree of a PopBTree node of the region, of level at most ℓ + 2 \ell+2 ℓ + 2 , and then by Lemma 34(4) has weight at least n / 3 ℓ + 1 + 1 = x / 3 + 1 n/3^{\ell+1}+1 = x/3+1 n / 3 ℓ + 1 + 1 = x /3 + 1 . Otherwise it contains no PopBTree child subtree at all, which by Lemma 34(5) forces the block, and u u u ’s whole subtree, to lie at leaf level, where every weight is bounded by an absolute constant (a merged leaf block has O ( 1 ) O(1) O ( 1 ) keys by Lemma 34 (2), comfortably below 729, so that the external or key-only subtree, of weight at least 1, meets the ratio. In the former case
x / 3 + 1 243 x + 1 ≥ 1 729 , \frac{x/3+1}{243x+1} \ge\frac{1}{729}, 243 x + 1 x /3 + 1 ≥ 729 1 ,
since 729 ( x / 3 + 1 ) = 243 x + 729 ≥ 243 x + 1 729(x/3+1)=243x+729 \ge243x+1 729 ( x /3 + 1 ) = 243 x + 729 ≥ 243 x + 1 .
We now present our main theorem.
Theorem 43. PopTree. There is an online algorithm maintaining a binary search tree over [ n ] [n] [ n ] , the PopTree, that uses only the unit-cost operations of the B B [ α ] BB[\alpha] B B [ α ] -algorithm model such that the tree is a B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] tree after every unit-cost operation, is a B B [ 1 20 ] BB[\frac{1}{20}] B B [ 20 1 ] tree after every search, and processes any search sequence X X X of length Ω ( n log n ) \Omega(n\log n) Ω ( n log n ) in total time O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) .
Proof. Run the PopBTree algorithm of Theorem 38 on the right-chain expansion. By Lemma 40 each of its pointer moves, promotions, and demotions is realized by O ( 1 ) O(1) O ( 1 ) unit-cost operations of the BST model and carries only a constant-factor overhead. Hence the work for the i i i th search, which is O ( ℓ i ( x i ) ) O(\ell_i(x_i)) O ( ℓ i ( x i )) on the PopBTree (Theorem 38 ), remains O ( ℓ i ( x i ) ) O(\ell_i(x_i)) O ( ℓ i ( x i )) on the PopTree, consistent with Lemma 39 , whereby the search descends to PopTree depth O ( ℓ i ( x i ) ) O(\ell_i(x_i)) O ( ℓ i ( x i )) . Summing over the sequence and applying Corollary 22,
∑ i O ( ℓ i ( x i ) ) = O ( O P T ( X ) ) for ∣ X ∣ = Ω ( n log n ) . \sum_i O(\ell_i(x_i)) = O(OPT(X)) \qquad\text{for } |X|=\Omega(n\log n). i ∑ O ( ℓ i ( x i )) = O ( O P T ( X )) for ∣ X ∣ = Ω ( n log n ) .
After every unit-cost operation the PopTree is a B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] tree by Lemma 42 , as the model demands of a valid B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -algorithm. Between searches the SkipPopList invariants hold, so the PopBTree is a B B B [ 1 12 ] BBB[\frac{1}{12}] B B B [ 12 1 ] tree by Lemma 33 and its expansion is a B B [ 1 20 ] BB[\frac{1}{20}] B B [ 20 1 ] tree by Lemma 41 . Thus the whole sequence is executed in O ( O P T ( X ) ) O(OPT(X)) O ( O P T ( X )) time by an algorithm that is at all times a valid B B [ 1 729 ] BB[\frac{1}{729}] B B [ 729 1 ] -algorithm.