Documentation

CslibFrontier.DataStructure.BPlusTree.Height

Height bounds for B+-trees #

The height of a well-formed B+-tree is logarithmic in its size. Every entry is in a leaf, so the count is of leaves: a balanced subtree of height h all of whose nodes are occupied has at least t ^ (h - 1) leaves, each holding at least t - 1 entries. The root of a well-formed tree of height at least 2 has at least two children, which gives 2 * (t - 1) * t ^ (h - 2) entries, and that is at least t ^ (h - 1) because 2 ≤ t.

height counts the nodes on a root-to-leaf path, so a leaf has height 1 and the bound is height ≤ Nat.log t size + 1. The empty tree is the empty leaf, of height 1 and size 0, and satisfies it. The lower bound on the size needs height at least 2: a root leaf may hold any number of entries up to 2 * t - 1, including none.

Main results #

References #

theorem Cslib.DataStructure.BPlusTree.le_size_node {α : Type u_1} {β : Type u_2} {first : BPlusTree α β} {rest : List (Branch α β)} {n : ℕ} (h₁ : n ≤ first.size) (h₂ : ∀ e ∈ rest, n ≤ e.child.size) :
(rest.length + 1) * n ≤ (first.node rest).size

A node whose children each hold at least n entries holds at least n for each child.

theorem Cslib.DataStructure.BPlusTree.Occupied.mul_pow_le_size {α : Type u_1} {β : Type u_2} {t : ℕ} {tr : BPlusTree α β} (ho : Occupied t tr) (hb : tr.Balanced) :
(t - 1) * t ^ (tr.height - 1) ≤ tr.size

A balanced occupied subtree of height h holds at least (t - 1) * t ^ (h - 1) entries: it has at least t ^ (h - 1) leaves, each with at least t - 1 entries.

theorem Cslib.DataStructure.BPlusTree.Balanced.pow_le_size {α : Type u_1} {β : Type u_2} {t : ℕ} {tr : BPlusTree α β} (hb : tr.Balanced) (ht : 2 ≤ t) (hw : (∀ (entries : List (α × β)), tr ≠ BPlusTree.leaf entries) → 1 ≤ tr.width) (ho : ∀ c ∈ tr.children, Occupied t c) (h2 : 2 ≤ tr.height) :
t ^ (tr.height - 1) ≤ tr.size

At a minimum degree of at least 2, a balanced tree of height h ≥ 2 whose root has a separator and whose children are occupied holds at least t ^ (h - 1) entries: the bound depends on the shape only, not on the keys.

theorem Cslib.DataStructure.BPlusTree.Balanced.height_le_log {α : Type u_1} {β : Type u_2} {t : ℕ} {tr : BPlusTree α β} (hb : tr.Balanced) (ht : 2 ≤ t) (hw : (∀ (entries : List (α × β)), tr ≠ BPlusTree.leaf entries) → 1 ≤ tr.width) (ho : ∀ c ∈ tr.children, Occupied t c) :
tr.height ≤ Nat.log t tr.size + 1

At a minimum degree of at least 2, the height of a balanced tree whose root has a separator and whose children are occupied is logarithmic in its size: the bound depends on the shape only, not on the keys.

theorem Cslib.DataStructure.BPlusTree.le_mul_height_add_of_scan {α : Type u_1} {β : Type u_2} {t c : ℕ} {f : BPlusTree α β → ℕ} (hleaf : ∀ (entries : List (α × β)), f (leaf entries) ≤ entries.length + c) (hnode : ∀ (first : BPlusTree α β) (rest : List (Branch α β)) (B : ℕ), (∀ ch ∈ (first.node rest).children, f ch ≤ B) → f (first.node rest) ≤ rest.length + B) {tr : BPlusTree α β} (hw : tr.width ≤ 2 * t - 1) (hc : ∀ ch ∈ tr.children, Occupied t ch) :
f tr ≤ (2 * t - 1) * tr.height + c

A count that spends at most one unit per entry and c more in a leaf, and at most one unit per separator at a node beyond what it spends in one of the node's children, is at most (2 * t - 1) * height + c on a tree whose root has width at most 2 * t - 1 and whose children are occupied.

theorem Cslib.DataStructure.BPlusTree.IsWF.pow_le_size {α : Type u_1} {β : Type u_2} {t : ℕ} {tr : BPlusTree α β} [LinearOrder α] (h : IsWF t tr) (h2 : 2 ≤ tr.height) :
t ^ (tr.height - 1) ≤ tr.size

A well-formed tree of height h ≥ 2 holds at least t ^ (h - 1) entries.

theorem Cslib.DataStructure.BPlusTree.IsWF.height_le_log {α : Type u_1} {β : Type u_2} {t : ℕ} {tr : BPlusTree α β} [LinearOrder α] (h : IsWF t tr) :
tr.height ≤ Nat.log t tr.size + 1

The height of a well-formed tree is logarithmic in its size.