Comparison lower bound for B-tree rank search #
Information-theoretic ⌈log₂(n + 1)⌉ comparison lower bound for rank queries on B-trees over an
infinite key type, in CSLib's FreeM (LEQuery α) query-complexity framework ([Knu98],
Section 6.2.1).
A comparison-based rank program can achieve logarithmic query complexity only when the input
tree's keys are strictly increasing under the oracle's linear order: a search that descends into
a single child per level misses out-of-order keys in sibling subtrees, and ranking an arbitrary
unsorted list of n keys requires n comparisons. Accordingly, IsRank requires that under any
oracle implementing a linear order r for which (tree.toList.map Prod.fst) is strictly
r-increasing, the program returns the number of entries strictly r-below the query key k.
Both B-tree rank implementations—rankQ (linear in-node scan) and rankBinQ (binary in-node
search)—satisfy IsRank (rankQ_isRank, rankBinQ_isRank).
Given any tree tree of size n with duplicate-free keys xs = tree.toList.map Prod.fst and a
fresh key k ∉ xs (obtained from [Infinite α]), inserting k at each of the n + 1 gap
positions 0, …, n of xs defines n + 1 linear orders on α. Every one of
these n + 1 linear orders keeps xs strictly increasing while giving k a distinct rank in
{0, …, n}. Applying FreeM.exists_countQueries_ge_clog to the binary-response query type
LEQuery α shows that at least one of those n + 1 oracles forces ⌈log₂(n + 1)⌉ comparisons
(rank_lowerBound_infinite). Bulk-loading n distinct keys via ofSortedList lifts this
per-tree bound to Cslib.Query.LowerBound both over arbitrary BTree α β × α inputs
(IsRank.lowerBound_infinite, requiring no ambient order on α) and over well-formed trees
WFInput α β t of minimum degree t ≥ 2 (IsRank.lowerBound_wfInput_infinite, matching
rankBinQ_upperBound_size so LowerBound.le_upperBound applies directly). The trees come from
exists_isWF_toList_map_snd_eq, which bulk-loads any prescribed list of values under distinct
increasing keys; the form over arbitrary inputs follows from the well-formed one under any linear
order on α.
This module covers comparison-based rank in FreeM (LEQuery α) (not machine-instruction lower
bounds). The companion comparison lower bound for lookup, in
CslibFrontier.DataStructure.BTree.Comparisons.LookupLowerBound, is proved for trees with
distinct values (its Cslib.Query.LowerBound forms assume an infinite value type); sets, whose
values are not distinct, are not covered and remain open under #3674. It needs oracles with
ties, because under linear orders alone equality is outside the oracle and a lookup program can
be correct without asking.
Main definitions #
Cslib.DataStructure.BTree.IsRank: correctness predicate for comparison-based B-tree rank programs against linear-order oracles on trees whose keys are strictly increasing.
Main results #
Cslib.DataStructure.BTree.rankQ_isRank,Cslib.DataStructure.BTree.rankBinQ_isRank: linear and binary in-node B-tree rank queries satisfyIsRank.Cslib.DataStructure.BTree.rank_lowerBound_infinite: on any tree of sizenwith distinct keys over an infinite key type, anyIsRankprogram makes at least⌈log₂(n + 1)⌉comparisons on some query key and comparison oracle.Cslib.DataStructure.BTree.IsRank.lowerBound_infinite:Cslib.Query.LowerBoundof⌈log₂(n + 1)⌉overBTree α β × αwith sizep.1.size.Cslib.DataStructure.BTree.IsRank.lowerBound_wfInput_infinite:Cslib.Query.LowerBoundof⌈log₂(n + 1)⌉over well-formed inputsWFInput α β t(2 ≤ t) with sizep.val.1.size.
References #
IsRank rankProg asserts that against every oracle implementing a linear order r under
which the keys of tree.toList are strictly increasing, rankProg k tree evaluates to the
number of entries of tree.toList whose key is strictly r-below k.
- correct (k : α) (tree : BTree α β) (oracle : {ι : Type} → Query.LEQuery α ι → ι) (r : α → α → Prop) [DecidableRel r] [IsLinearOrder α r] : (∀ (a b : α), oracle (Query.LEQuery.le a b) = decide (r a b)) → List.Pairwise (fun (a b : α) => r a b ∧ ¬r b a) (List.map Prod.fst tree.toList) → FreeM.eval (fun {ι : Type} => oracle) (rankProg k tree) = (List.filter (fun (x : α × β) => decide (r x.1 k ∧ ¬r k x.1)) tree.toList).length
Under a linear-order oracle that strictly orders
tree.toList's keys,rankProg k treecounts the entries strictly belowk.
rankQ (linear in-node search) is a correct comparison-based rank program.
rankBinQ (binary in-node search) is a correct comparison-based rank program.
Per-tree comparison lower bound for rank. On any B-tree tree with distinct keys over an
infinite key type α, any IsRank program makes at least ⌈log₂(tree.size + 1)⌉ comparisons
for some query key k and comparison oracle.
Comparison lower bound for B-tree rank over well-formed inputs (WFInput). When 2 ≤ t,
any IsRank program restricted to well-formed B-trees of minimum degree t (WFInput α β t,
matching rankBinQ_upperBound_size) still has worst-case comparison query complexity at least
⌈log₂(n + 1)⌉ at every input size n.
Comparison lower bound for B-tree rank (Cslib.Query.LowerBound). Any IsRank program on
an infinite key type α and nonempty value type β has worst-case comparison query complexity at
least ⌈log₂(n + 1)⌉ on trees of size at most n.