Comparison cost of B-tree closed-interval queries #
rangeQ instantiates rangeM in CSLib's query-complexity framework, at FreeM (LEQuery α) with
the comparison query LEQuery.ask and the trivial visit := pure (). eval_rangeQ identifies
its value under orderOracle with range, through the transfer lemma
Cslib.IsMonadHom.map_rangeM.
The scan of a node compares each separator it reaches with both bounds, so one visited node can
cost 2 * (2 * t - 1) comparisons: the per-node bound of 2 * t behind the point-query bounds
fails, and the node-visit bound of time_rangeT cannot simply be multiplied by it. The count is
bounded instead by charging two comparisons to every returned entry and the rest to the two
boundary paths. countQueries_rangeQ_of_occupied proves at most 4 * t * height + 2 * k
comparisons, where k is the length of the output, on any tree with sorted entries, at most
2 * t - 1 root keys and children occupied for some t > 0, through three auxiliary bounds by
recursion on the tree:
- a subtree whose entries all lie in the interval costs two comparisons per returned entry;
- a subtree whose keys are all at least
locosts at most two more per level, for the separator abovehithat stops each scan on the path towardshi; - a subtree whose keys are all at most
hicosts at most2 * (2 * t - 1)more per level, for the separators belowloon the path towardslo.
countQueries_rangeQ_le restates the bound on well-formed trees as
2 * t * (2 * height + k), and countQueries_rangeQ_le_log composes it with
IsWF.height_le_log. The bounds are stated at the order's oracle only: under another oracle
the output is not the output under ≤, so a bound in its length is not meaningful.
Main definitions #
rangeQ: B-tree closed-interval query counting comparisons.
Main results #
countQueries_rangeQ_le: the number of comparisons made byrangeQis at most2 * t * (2 * tr.height + (range lo hi tr).length).eval_rangeQ: the value ofrangeQevaluated at the order oracle matchesrange.
References #
Ported from cslib-community/EpsilonEridani PR #39 at commit 9425389c8.
Closed-interval query, issuing one query per key comparison.
Under the order's oracle, rangeQ evaluates to range.
The empty tree costs no comparison.
A node without keys costs what its only child costs.
The first separator is compared with both bounds; the child before it is searched when the
separator is at least lo, and the remaining triples are scanned, as the node without its first
child and separator, when the separator is at most hi.
Auxiliary bounds #
Comparison bounds #
A closed-interval query makes at most 4 * t * height + 2 * k comparisons, where k is the
number of entries it returns, on any tree with sorted entries, at most 2 * t - 1 root keys and
children occupied for some t > 0. Each returned entry costs two comparisons; at each level,
the path towards lo costs at most 2 * (2 * t - 1) more and the path towards hi at most
two.
A closed-interval query on a well-formed tree makes at most 2 * t * (2 * height + k)
comparisons, where k is the number of entries it returns: the node-visit bound 2 * height + k
of time_rangeT times 2 * t. A single node can cost more than 2 * t comparisons, so this is
a consequence of countQueries_rangeQ_of_occupied, not a per-node bound.
A closed-interval query on a well-formed tree makes logarithmically many comparisons beyond
2 * t per entry it returns.