Pointer-and-Rotation BST Access Model, Touched Subtrees, and Dynamic Optimality #
This module formalizes the standard pointer-and-rotation binary search tree (BST) access model of
[ST85b] and [Wil89] directly over Mathlib's BinaryTree α, reusing
Cslib.DataStructure.SearchTree.Ordered, Cslib.DataStructure.SearchTree.elements, and the
zipper structures Frame, plug, and Focus from Cslib.DataStructure.SplayTree.Basic.
Execution models and cost measures #
Atomic pointer-and-rotation model (
BSTStep,BSTAccess,BSTExecution): To serve a successful accessx ∈ elements tstarting from an ordered treet, a pointer starts at the root (Focus.ofTree? t) and executes a finite sequence of unit-cost atomic steps: moving to a left child (moveLeft), right child (moveRight), or parent (moveUp), or rotating the focused node with its parent (rotateUp). The pointer must visitxduring the step sequence (x ∈ touched). Two natural cost measures are recorded:stepCost:steps.length + 1per access (one unit for starting at the root plus one per atomic pointer move or rotation).touchedCost:touched.cardper access (number of distinct nodes visited by the pointer). Every execution satisfiesxs.length ≤ e.touchedCost ≤ e.stepCost.
Touched-subtree model (
UntouchedPreserved,TouchedStep,TouchedExecution): Abstracting the atomic pointer trace, each access chooses an upward-closed connected top subtreeτ(containing the root and the accessed keyx) in bothtandt', and restructures only withinτwhile leaving every untouched node's subtree (u ∉ τ) identical. EveryBSTExecutioninduces aTouchedExecutionof coste.touchedCost(toTouchedExecution), so lower bounds proved forTouchedExecution(such as Wilber's first and second lower bounds) hold simultaneously for bothtouchedCostandstepCostof arbitrary pointer-and-rotation executions.Splay trees as an online BST strategy (
OnlineBSTStrategy,splayStrategy): Bottom-up splaying (SplayTree.splay) is compiled explicitly to atomicBSTStepsequences (splaySteps), producing a computable statelessOnlineBSTStrategywhose final tree agrees identically withsplaySeqand whosetouchedCostandstepCostlie within explicit constant factors (1..2and1..4) of Sleator–Tarjan's rotation-plus-one access costsplaySeqCost.Dynamic Optimality Conjecture (
IsDynamicallyOptimal,DynamicOptimalityConjecture): States Sleator and Tarjan's conjectural dynamic optimality of splay trees against all offline pointer-and-rotation executions up to a universal constant factor andO(|t₀|)additive term.
Main definitions #
subtreeAt,Ancestor,IsUpperSet,OrderConvex,topNode: BST subtree lookup, ancestry, upward-closed subsets, order-convexity, and lowest common ancestor of an order-convex key set.BSTStep,Focus.applyStep?,runSteps,BSTAccess,BSTExecution: atomic pointer-and-rotation BST execution model withstepCostandtouchedCost.UntouchedPreserved,TouchedStep,TouchedExecution: connected touched-subtree execution model.OnlineBSTStrategy,splaySteps,splayAccess,splayStrategy: online BST strategies and the explicit compilation of bottom-up splaying intoBSTSteps.IsDynamicallyOptimal,DynamicOptimalityConjecture: dynamic optimality predicate and the Dynamic Optimality Conjecture for splay trees.
Main results #
topNode_eq_some_of_orderConvex,topNode_eq_some_of_ancestor: existence and uniqueness of the highest node (topNode) of any nonempty order-convex key subset in an ordered BST.BSTExecution.toTouchedExecution,BSTExecution.touchedCost_le_stepCost: every atomic pointer-and-rotation execution induces a validTouchedExecutionwithcost = touchedCost ≤ stepCost.splayStrategy_finalTree,splaySeqCost_le_splayStrategy_touchedCost,splayStrategy_touchedCost_le,splaySeqCost_le_splayStrategy_stepCost,splayStrategy_stepCost_le: exact simulation ofSplayTree.splaySeqbysplayStrategywith explicit constant-factor cost equivalence.
References #
- [ST85b] Daniel Dominic Sleator and Robert Endre Tarjan, Self-Adjusting Binary Search Trees, Journal of the ACM 32(3), 1985.
- [Wil89] Robert Wilber, Lower Bounds for Accessing Binary Search Trees with Rotations, SIAM Journal on Computing 18(1), 56–67, 1989 (cited at topic level; journal full text not inspected).
The subtree of t rooted at key x (found by BST search), or .nil if x is not found.
Every key in subtreeAt x t belongs to elements t.
subtreeAt x t preserves the strict BST invariant Ordered.
In an Ordered tree, subtreeAt x t is nonempty at root x iff x ∈ elements t.
In an Ordered tree, subtreeAt x t = .nil iff x ∉ elements t.
In an Ordered tree, x is the root of subtreeAt x t whenever x ∈ elements t.
Ancestry relation in a BST: u is an ancestor of v in t iff v lies in subtreeAt u t.
Note that this requires u ∈ elements t (otherwise subtreeAt u t = .nil).
If v lies in subtreeAt u t, then searching for v inside subtreeAt u t yields the same
subtree as searching in t.
Two ancestors of a common node in an Ordered BST are comparable in the ancestor order.
A subset τ of keys is upward-closed in t if every ancestor of a key in τ is also in
τ.
A subset A is order-convex in a key set s if every key of s lying strictly between two
keys of A also belongs to A.
Every subtree of an Ordered BST has an order-convex element set inside elements t.
Highest (closest-to-root) node of t whose key lies in A. On an Ordered tree and an
order-convex nonempty subset A ⊆ elements t, this is the unique lowest common ancestor of A.
In an Ordered BST, any nonempty order-convex subset A ⊆ elements t has a unique highest
node v ∈ A (topNode A t = some v), which is an ancestor of every key in A.
Uniqueness characterization of topNode: if v ∈ A is an ancestor of every key of A in an
Ordered BST t, then topNode A t = some v.
Zipper-Context Keys and Subtree Invariance under plug #
Atomic Pointer-and-Rotation BST Model and Touched-Subtree Model #
Atomic unit-cost steps of a pointer-and-rotation BST machine ([ST85b], [Wil89]): move the pointer to its left child, right child, or parent, or rotate the focused node with its parent (keeping the pointer on the rotated node).
- moveLeft : BSTStep
Move the pointer to the left child of the focused node.
- moveRight : BSTStep
Move the pointer to the right child of the focused node.
- moveUp : BSTStep
Move the pointer to the parent of the focused node.
- rotateUp : BSTStep
Rotate the edge between the focused node and its parent, keeping the pointer on the focused node.
Instances For
Initialize a focus at the root of a non-empty BinaryTree α.
Touched-subtree preservation invariant between an initial BST t and a restructured BST t'
with touched key set τ: the key set is unchanged, τ is upward-closed in both t and t', and
every untouched key (u ∉ τ) retains its exact subtree.
Restructuring preserves the stored set of keys.
- touched_subset : τ ⊆ SearchTree.elements t
Every touched key belongs to the tree.
- upper_before : IsUpperSet t τ
τis upward-closed (connected to the root) int. - upper_after : IsUpperSet t' τ
τis upward-closed (connected to the root) int'. Every untouched node retains its exact subtree.
Every sequence of atomic BSTSteps starting from the root of an Ordered tree t preserves
Ordered and satisfies UntouchedPreserved t f'.toTree τ.
A valid single-access transition from t to t' serving key x in the atomic
pointer-and-rotation BST model: starting at the root, executing steps visits x (x ∈ touched)
and produces t'.
- rootFocus : Focus α
Initial focus at the root of
t. Atomic pointer moves and rotations executed during the access.
- finalFocus : Focus α
Final pointer focus after executing
steps. - touched : Finset α
Set of distinct keys visited by the pointer during
steps. Execution starts at the root of
t.- hrun : runSteps self.rootFocus {self.rootFocus.key} self.steps = some (self.finalFocus, self.touched)
Running
stepsfrom the root succeeds with final focus and touched key set. The resulting tree is
t'.The accessed key
xis visited during the access.
Atomic step cost of a single access: 1 for initializing the pointer at the root plus one per
atomic move or rotation.
Touched-node cost of a single access: the number of distinct nodes visited by the pointer.
A valid pointer-and-rotation BST execution serving an access sequence xs from initial tree
t.
- nil {α : Type u_1} [LinearOrder α] (t : BinaryTree α) : BSTExecution t []
Empty access sequence leaves
tunchanged at zero cost. - cons {α : Type u_1} [LinearOrder α] {t t' : BinaryTree α} {x : α} {xs : List α} (head : BSTAccess t x t') (tail : BSTExecution t' xs) : BSTExecution t (x :: xs)
Serve
xby an atomic accesst ↦ t', then serve the remaining sequencexsfromt'.
Final tree after a BSTExecution.
Total atomic step cost across a BSTExecution.
Total touched-node cost across a BSTExecution.
Single step in the touched-subtree BST model: an upward-closed set touched containing x
is restructured arbitrarily while leaving all untouched subtrees identical.
- touched : Finset α
Upward-closed touched top subtree.
- ordered_after : SearchTree.Ordered t'
Resulting tree satisfies
Ordered. - preserved : UntouchedPreserved t t' self.touched
Untouched nodes preserve their subtrees and
touchedis upward-closed before and after. The accessed key
xlies intouched.
Sequence of touched-subtree steps serving xs from t.
- nil {α : Type u_1} [LinearOrder α] (t : BinaryTree α) : TouchedExecution t []
Empty access sequence leaves
tunchanged at zero cost. - cons {α : Type u_1} [LinearOrder α] {t t' : BinaryTree α} {x : α} {xs : List α} (head : TouchedStep t x t') (tail : TouchedExecution t' xs) : TouchedExecution t (x :: xs)
One touched-subtree step followed by the remainder of the sequence.
Total touched-node cost of a TouchedExecution.
The BST before step i (and the final tree at i = xs.length) along a TouchedExecution.
The touched key set τ_i at step i of a TouchedExecution.
Every atomic BSTAccess induces a TouchedStep with the exact same touched node set.
Every atomic BSTExecution induces a TouchedExecution of cost e.touchedCost.
Online BST Strategies, Splay-Tree Compilation, and Dynamic Optimality #
An online BST strategy maintaining internal memory Mem and serving each request x
with an atomic BSTAccess depending only on the current tree, internal memory, and x.
- Mem : Type
Auxiliary internal state maintained by the strategy.
- init : BinaryTree α → self.Mem
Initial internal state given the initial BST.
Invariant tying the concrete BST to internal memory.
The invariant holds on every ordered initial tree.
- serve {t : BinaryTree α} (m : self.Mem) (x : α) : SearchTree.Ordered t → self.Inv t m → x ∈ SearchTree.elements t → (t' : BinaryTree α) × BSTAccess t x t' × { m' : self.Mem // self.Inv t' m' }
Serve a single successful access
x ∈ elements tonline.
Run an OnlineBSTStrategy from a given internal state on an access sequence xs.
Execute an OnlineBSTStrategy from an ordered initial tree t₀.
Downward pointer moves following the search path of focusSearch x t [].
Full atomic BSTStep sequence implementing SplayTree.splay x t.
Compile a single bottom-up SplayTree.splay x t on a present key x ∈ elements t into an
explicit atomic BSTAccess t x (splay x t).tree.
splayAccess executes the exact atomic step sequence produced by splaySteps.
Stateless computable online BST strategy implementing Sleator and Tarjan's bottom-up splay trees ([ST85b]).
Executing splayStrategy on xs produces the exact final tree of SplayTree.splaySeq.
splayStrategy's touched-node cost is lower-bounded by Sleator–Tarjan's rotation-plus-one
access cost splaySeqCost.
splayStrategy's touched-node cost is at most 2 * splaySeqCost.
splayStrategy's atomic step cost is lower-bounded by splaySeqCost.
splayStrategy's atomic step cost is at most 4 * splaySeqCost.
Dynamic Optimality Conjecture #
An online BST strategy family is dynamically optimal if there exists a universal constant
c such that on every linearly ordered key type α, every ordered initial BST t₀, every
successful access sequence xs of keys in t₀, and every valid (possibly offline)
pointer-and-rotation execution e serving xs from any ordered initial tree t₀' storing the
same key set, the strategy's step cost is at most c * (e.stepCost + (elements t₀).card).
Dynamic Optimality Conjecture for splay trees ([ST85b]):
bottom-up splay trees (splayStrategy) are dynamically optimal among all pointer-and-rotation
BST executions. By splaySeqCost_le_splayStrategy_stepCost and splayStrategy_stepCost_le,
this is equivalent up to a factor of 4 to comparing Sleator–Tarjan's rotation-plus-one access
cost splaySeqCost xs t₀ against e.stepCost + (elements t₀).card.