Documentation

CslibFrontier.DataStructure.SplayTree.WorkingSet

Splay-Tree Static Finger and Working-Set Theorems #

This module proves two locality bounds of Sleator and Tarjan for sequences of accesses to keys present in a splay tree, with explicit constants in the rotation-plus-one access-cost model splaySeqCost (each access costs splayCost = max rotations 1 BST rotations, [ST85b], Section 2, p. 658, rather than Word-RAM or Turing-machine instructions). Both follow from the Access Lemma with inverse-square weights. The static finger weights 1/(d + 1)² total at most 2 + 1 = 3: the keys at or below f have distinct distances d ≥ 0 and contribute at most ∑_{k ≥ 1} 1/k² ≤ 2, and the keys above f have distinct distances d ≥ 1 and contribute at most ∑_{k ≥ 2} 1/k² ≤ 1. The working-set weights 1/(t + 1)² total at most ∑_{k ≥ 1} 1/k² ≤ 2.

Main definitions #

Main results #

Both theorems assume every access is to a key stored in the tree, as in the source's analysis of item accesses; unsuccessful searches are not covered.

References #

Inverse-Square Sums and Binary-Logarithm Helper #

Static Finger Theorem #

def Cslib.DataStructure.SplayTree.fingerDist {α : Type u_1} [LinearOrder α] (s : Finset α) (f y : α) :

Symmetric-order distance from the finger f to y among the keys s: the number of keys of s in [y, f) when y ≤ f, and in (f, y] when f < y. For s = {1, …, n} and f, y ∈ s this is |y - f|, the distance in [ST85b], Section 2, Theorem 3, p. 659.

theorem Cslib.DataStructure.SplayTree.fingerDist_lt_card {α : Type u_1} [LinearOrder α] {s : Finset α} {f : α} (hf : f ∈ s) (y : α) :
fingerDist s f y < s.card

The finger distance between keys of s is less than |s|: the counted keys exclude f.

theorem Cslib.DataStructure.SplayTree.splaySeqCost_le_static_finger {α : Type u_1} [LinearOrder α] (xs : List α) {t : BinaryTree α} (ht : SearchTree.Ordered t) (hxs : ∀ x ∈ xs, x ∈ SearchTree.elements t) {f : α} (hf : f ∈ SearchTree.elements t) :
↑(splaySeqCost xs t) ≤ 7 * ↑xs.length + 6 * (List.map (fun (x : α) => Real.logb 2 (↑(fingerDist (SearchTree.elements t) f x) + 1)) xs).sum + ↑(SearchTree.elements t).card * (2 + 2 * Real.logb 2 ↑(SearchTree.elements t).card)

Static Finger Theorem ([ST85b], Section 2, Theorem 3, p. 659): let t be an Ordered splay tree with n = |t| keys and f ∈ t a fixed key. A sequence xs of m accesses to keys of t has total rotation-plus-one access cost (splaySeqCost) at most 7m + 6 ∑ⱼ log₂(d(xⱼ) + 1) + n (2 + 2 log₂ n), where d = fingerDist (elements t) f is the symmetric-order distance to f. The proof assigns static weights 1/(d(y) + 1)², with total at most 3.

Working-Set Numbers and Move-to-Front Ranks #

def Cslib.DataStructure.SplayTree.recencyRank {α : Type u_1} [DecidableEq α] (x : α) (l : List α) :

The number of distinct keys before the first occurrence of x in l (all distinct keys of l when x ∉ l). For a duplicate-free l this is the position of x in l; for a reversed access history it is the position of x in the move-to-front list ([ST85b], Section 2, p. 659).

Sleator–Tarjan working-set numbers ([ST85b], Section 2, p. 659): entry j is t(j), the number of different keys accessed before access j since the last access of xs[j], or since the beginning of the sequence if access j is the first access of xs[j]. The reversed prefix lists earlier accesses from the most recent; recencyRank counts the distinct keys before the most recent earlier access of xs[j].

Working Set Theorem #

theorem Cslib.DataStructure.SplayTree.splaySeqCost_le_working_set {α : Type u_1} [LinearOrder α] (xs : List α) {t : BinaryTree α} (ht : SearchTree.Ordered t) (hxs : ∀ x ∈ xs, x ∈ SearchTree.elements t) :
↑(splaySeqCost xs t) ≤ 4 * ↑xs.length + 6 * (List.map (fun (k : ℕ) => Real.logb 2 (↑k + 1)) (workingSetNumbers xs)).sum + ↑(SearchTree.elements t).card * (1 + 2 * Real.logb 2 ↑(SearchTree.elements t).card)

Working Set Theorem ([ST85b], Section 2, Theorem 4, pp. 659–660): let t be an Ordered splay tree with n = |t| keys. A sequence xs of m accesses to keys of t has total rotation-plus-one access cost (splaySeqCost) at most 4m + 6 ∑ⱼ log₂(t(j) + 1) + n (1 + 2 log₂ n), where t(j) = (workingSetNumbers xs)[j] is the number of different keys accessed before access j since the last access of xs[j], or since the beginning if access j is the first access of xs[j].

The proof follows Sleator and Tarjan: the weights 1, 1/4, …, 1/n² are assigned in move-to-front order (initially in order of first access, never-accessed keys last), so the key accessed at step j has weight 1/(t(j) + 1)² and the total weight is at most 2. After each access the weights are reassigned with the accessed key, now at the root, moved to the front; this reassignment keeps the root size and decreases every other size, so it does not increase the potential.