Size and height of classic B-trees #
The three inequalities relating the size and height of a well-formed classic B-tree of minimum
degree t, after [CLRS09], Chapter 18. They follow from the corresponding bounds for non-root
subtrees, Occupied.pow_sub_one_le_size and Occupied.size_le. These are structural facts about
the shape of a tree; they carry no cost content.
Main results #
IsWF.le_size: a non-empty tree of heighthhas at least2 * t ^ (h - 1) - 1entries.IsWF.size_le: a tree of heighthhas at most(2 * t) ^ h - 1entries.IsWF.height_le_log: the height is at mostNat.log t ((size + 1) / 2) + 1, the bound of [CLRS09], Theorem 18.1, with heights counted in nodes rather than edges.Balanced.height_le_log: the same bound from the shape alone, without key order.le_mul_height_of_node_le: a count on trees that spends at mostcat each node along a descent is at mostc * height.le_mul_height_of_scan: its instance for a count that spends at most one more than a node's key count at each node, which is at most2 * t * height.
References #
Ported from cslib-community/EpsilonEridani at commit 1966ab476:
EpsilonEridani/Algorithms/Lean/BTree/Height.lean.
le_mul_height_of_scan ported from cslib-community/EpsilonEridani PR #39 at commit 9425389c8.
Nodes #
A node whose children each hold at most n - 1 entries, for positive n, holds at most
(rest.length + 1) * n - 1.
Bounds #
A non-empty balanced tree of height h with a key at the root and occupied children holds at
least 2 * t ^ (h - 1) - 1 entries. Only the shape matters, not the order of the keys.
The height of a balanced tree with a key at a non-empty root and occupied children is
logarithmic in its size, for 2 ≤ t. Only the shape matters, not the order of the keys.
Counts along a descent #
A count on trees that spends at most c at a node with at most 2 * t - 1 keys beyond what
it spends in one of the node's children, and nothing on the empty tree, is at most c * height
on a tree whose root holds at most 2 * t - 1 keys and whose children are occupied.
A count on trees that spends at most rest.length + 1 at a node .node first rest beyond
what it spends in one of the node's children, and nothing on the empty tree, is at most
2 * t * height, for positive t, on a tree whose root holds at most 2 * t - 1 keys and whose
children are occupied.