Comparison costs of B-tree point queries #
The point queries of Cslib.DataStructure.BTree are defined once over a monad,
with a comparator and a node-visit action. This file instantiates them in
CSLib's query-complexity framework, at FreeM (LEQuery α) with the
comparison query LEQuery.ask and the trivial visit := pure (),
so that every key comparison is a query and node visits are free: lookupQ, containsQ,
minQ, maxQ, predQ, succQ and rankQ. Counting is structural: a program parametric in
the oracle cannot compare keys without asking.
Applied to FreeM.isMonadHom_pure_eval, the transfer lemmas Cslib.IsMonadHom.map_lookupM and
its siblings give eval_lookupQ and its siblings: under orderOracle, the oracle of the order
on the keys, each query evaluates to the pure query.
A query scans the keys of a node, one comparison per key passed, and descends into one child;
lookup spends one more comparison to test equality. le_mul_height_of_scan turns such a
per-node bound of rest.length + 1 into 2 * t * height on a tree whose root holds at most
2 * t - 1 keys and whose children are occupied, which is every well-formed tree. The
resulting bounds, countQueries_lookupQ_le and its siblings, hold for every oracle, since the
shape of the tree does not depend on the answers; lookupQ_upperBound and its siblings restate
them as Cslib.Query.UpperBound over well-formed inputs; lookupQ_upperBound_size and
rankQ_upperBound_size bound the cost in the number of entries instead, a bound monotone in
that number by monotone_mul_log_size. The minimum and maximum make no comparisons at all.
countQueries_slotM_le bounds the within-node linear search by one comparison per key. The bound
is the comparison analysis of B-TREE-SEARCH in [CLRS09], Section 18.2.
Main definitions #
Main results #
countQueries_lookupQ_le: the number of comparisons made bylookupQis at most2 * t * height.lookupQ_upperBound_size,rankQ_upperBound_size: the bound2 * t * (log_t ((n + 1) / 2) + 1)in the numbernof entries.eval_lookupQ: the value oflookupQevaluated at the order oracle matcheslookup.- (and similarly for the other queries)
References #
Ported from cslib-community/EpsilonEridani PR #39 at commit 9425389c8.
Lookup, issuing one query per key comparison.
Membership test, issuing one query per key comparison.
Least entry in the comparison model, where it asks nothing.
Greatest entry in the comparison model, where it asks nothing.
Strict predecessor, issuing one query per key comparison.
Strict successor, issuing one query per key comparison.
Rank, issuing one query per key comparison.
Transfer: eval at the order's oracle is the pure operation #
Under any oracle, minQ evaluates to min?.
Under any oracle, maxQ evaluates to max?.
The oracle of the order on the keys.
Under the order's oracle, lookupQ evaluates to lookup.
Under the order's oracle, containsQ evaluates to contains.
Under the order's oracle, predQ evaluates to pred?.
Under the order's oracle, succQ evaluates to succ?.
Under the order's oracle, rankQ evaluates to rank.
Comparison counts #
The within-node linear search makes at most one comparison per key.
The minimum search makes no comparison.
The maximum search makes no comparison.
Lookup in the empty tree makes no comparison.
Predecessor search in the empty tree makes no comparison.
Successor search in the empty tree makes no comparison.
Rank in the empty tree makes no comparison.
Lookup at a node makes at most one comparison per key and one more beyond what it makes in the child it descends into.
Predecessor search at a node makes at most one more comparison than the node has keys, beyond what it makes in the child it descends into.
Successor search at a node makes at most one more comparison than the node has keys, beyond what it makes in the child it descends into.
Rank at a node makes at most one more comparison than the node has keys, beyond what it makes in the child it descends into.
The membership test makes as many comparisons as lookup.
Comparison bounds #
Lookup in a well-formed tree makes at most 2 * t comparisons per level, under every
oracle.
The membership test in a well-formed tree makes at most 2 * t comparisons per level,
under every oracle.
Predecessor search in a well-formed tree makes at most 2 * t comparisons per level,
under every oracle.
Successor search in a well-formed tree makes at most 2 * t comparisons per level, under
every oracle.
Rank in a well-formed tree makes at most 2 * t comparisons per level, under every
oracle.
Lookup in a well-formed tree makes logarithmically many comparisons.
The membership test in a well-formed tree makes logarithmically many comparisons.
Predecessor search in a well-formed tree makes logarithmically many comparisons.
Successor search in a well-formed tree makes logarithmically many comparisons.
Rank in a well-formed tree makes logarithmically many comparisons.
Upper bounds over all oracles #
A well-formed tree of minimum degree t and a query key: the inputs of the bounded
point queries.
Lookup makes at most 2 * t comparisons at each of at most height nodes.
The membership test makes at most 2 * t comparisons at each of at most height nodes.
Predecessor search makes at most 2 * t comparisons at each of at most height nodes.
Successor search makes at most 2 * t comparisons at each of at most height nodes.
Rank makes at most 2 * t comparisons at each of at most height nodes.
Lookup in a well-formed tree of at most n entries makes at most
2 * t * (log_t ((n + 1) / 2) + 1) comparisons.
Rank in a well-formed tree of at most n entries makes at most
2 * t * (log_t ((n + 1) / 2) + 1) comparisons.