Comparison costs of B-tree queries with binary in-node search #
This file instantiates lookupBinM and rankBinM in CSLib's query-complexity framework, at
FreeM (LEQuery α) with the comparison query LEQuery.ask and the trivial visit := pure (),
as Comparisons.Query does for the linear scans. Every key comparison is a query.
Bisecting n keys takes at most ⌈log₂ (n + 1)⌉ comparisons, on any list and under any
oracle (countQueries_slotBinM_le). A node of a well-formed tree of minimum degree t holds at
most 2 * t - 1 keys, so the search costs at most ⌈log₂ (2 * t)⌉ comparisons per node. Rank
needs nothing more; lookup spends one further comparison to test the key found for equality.
le_mul_height_of_node_le sums the per-node cost along the descent. The bounds hold for every
oracle, since the shape of the tree does not depend on the answers. Under orderOracle the
programs evaluate to the pure lookupBin and rankBin, which are lookup and rank on trees
with sorted entries (lookupBin_eq_lookup, rankBin_eq_rank).
The linear scans of Comparisons.Query are bounded by 2 * t * height comparisons, so
bisection replaces the factor 2 * t by ⌈log₂ (2 * t)⌉ + 1.
Composed with the height bound IsWF.height_le_log, the counts become bounds in the number n
of entries: at most (⌈log₂ (2 * t)⌉ + 1) * (log_t ((n + 1) / 2) + 1) comparisons for lookup
and ⌈log₂ (2 * t)⌉ * (log_t ((n + 1) / 2) + 1) for rank, with the dependence on t
explicit. For fixed t and n ≥ 1 both are within a constant factor of ⌈log₂ (n + 1)⌉.
They are stated for every well-formed tree, and as UpperBound statements whose size function
is size. They are also stated for the tree bulk-loaded from any list of n entries, sorted or
not: like the answers of the oracle, the order of the keys does not change the shape of the
tree, and the counts need only the shape (countQueries_lookupBinQ_le_of_occupied,
countQueries_rankBinQ_le_of_occupied).
The statements are original to this development; no lower bound is proved here.
Main definitions #
lookupBinQ,rankBinQ: lookup and rank by binary in-node search, counting comparisons.
Main results #
countQueries_slotBinM_le: bisectingnkeys makes at most⌈log₂ (n + 1)⌉comparisons.countQueries_lookupBinQ_le,lookupBinQ_upperBound:lookupBinQmakes at most(⌈log₂ (2 * t)⌉ + 1) * heightcomparisons on a well-formed tree.countQueries_rankBinQ_le,rankBinQ_upperBound:rankBinQmakes at most⌈log₂ (2 * t)⌉ * heightcomparisons on a well-formed tree.countQueries_lookupBinQ_le_log,countQueries_rankBinQ_le_log: the same counts in the number of entries, throughIsWF.height_le_log.countQueries_lookupBinQ_le_of_occupied,countQueries_rankBinQ_le_of_occupied: the counts per level from the shape of the tree alone, without sorted keys.countQueries_lookupBinQ_ofSortedList_le,countQueries_rankBinQ_ofSortedList_le: the counts on a tree bulk-loaded from any list, in the length of the list.lookupBinQ_upperBound_size,rankBinQ_upperBound_size: the bounds in the number of entries over all oracles.
Lookup by binary in-node search, issuing one query per key comparison.
lookupBinQ is the FreeM (LEQuery α) instantiation of lookupBinM.
Rank by binary in-node search, issuing one query per key comparison.
Under the order's oracle, lookupBinQ evaluates to the pure lookupBin.
Under the order's oracle, rankBinQ evaluates to the pure rankBin.
Comparison counts #
The within-node binary search makes at most ⌈log₂ (n + 1)⌉ comparisons on n keys, sorted
or not, under every oracle.
Lookup by binary in-node search makes at most ⌈log₂ (2 * t)⌉ + 1 comparisons per level,
under every oracle, in a tree whose root holds at most 2 * t - 1 keys and whose children are
occupied. The keys need not be sorted.
Rank by binary in-node search makes at most ⌈log₂ (2 * t)⌉ comparisons per level, under
every oracle, in a tree whose root holds at most 2 * t - 1 keys and whose children are
occupied. The keys need not be sorted.
Lookup by binary in-node search in the tree bulk-loaded from a list of n entries makes at
most (⌈log₂ (2 * t)⌉ + 1) * (log_t ((n + 1) / 2) + 1) comparisons, under every oracle. The
list need not be sorted: the shape of the tree does not depend on the keys.
Rank by binary in-node search in the tree bulk-loaded from a list of n entries makes at
most ⌈log₂ (2 * t)⌉ * (log_t ((n + 1) / 2) + 1) comparisons, under every oracle. The list
need not be sorted.
Lookup by binary in-node search in a well-formed tree makes at most ⌈log₂ (2 * t)⌉ + 1
comparisons per level, under every oracle.
Rank by binary in-node search in a well-formed tree makes at most ⌈log₂ (2 * t)⌉
comparisons per level, under every oracle.
Bounds in the number of entries #
Lookup by binary in-node search in a well-formed tree of n entries makes at most
(⌈log₂ (2 * t)⌉ + 1) * (log_t ((n + 1) / 2) + 1) comparisons, under every oracle.
Rank by binary in-node search in a well-formed tree of n entries makes at most
⌈log₂ (2 * t)⌉ * (log_t ((n + 1) / 2) + 1) comparisons, under every oracle.
Upper bounds over all oracles #
Lookup by binary in-node search makes at most ⌈log₂ (2 * t)⌉ + 1 comparisons at each of at
most height nodes.
Rank by binary in-node search makes at most ⌈log₂ (2 * t)⌉ comparisons at each of at most
height nodes.
Lookup by binary in-node search in a well-formed tree of at most n entries makes at most
(⌈log₂ (2 * t)⌉ + 1) * (log_t ((n + 1) / 2) + 1) comparisons.
Rank by binary in-node search in a well-formed tree of at most n entries makes at most
⌈log₂ (2 * t)⌉ * (log_t ((n + 1) / 2) + 1) comparisons.