Documentation

Batteries.Data.RBMap.Depth

RBNode depth bounds #

O(n). depth t is the maximum number of nodes on any path to a leaf. It is an upper bound on most tree operations.

Equations
theorem Batteries.RBNode.size_lt_depth {α : Type u_1} (t : Batteries.RBNode α) :
t.size < 2 ^ t.depth

depthLB c n is the best upper bound on the depth of any balanced red-black tree with root colored c and black-height n.

Equations

depthUB c n is the best upper bound on the depth of any balanced red-black tree with root colored c and black-height n.

Equations
theorem Batteries.RBNode.Balanced.depth_le {α : Type u_1} {t : Batteries.RBNode α} {c : Batteries.RBColor} {n : Nat} :
t.Balanced c nt.depth Batteries.RBNode.depthUB c n
theorem Batteries.RBNode.Balanced.le_size {α : Type u_1} {t : Batteries.RBNode α} {c : Batteries.RBColor} {n : Nat} :
t.Balanced c n2 ^ Batteries.RBNode.depthLB c n t.size + 1
theorem Batteries.RBNode.Balanced.depth_bound {α : Type u_1} {t : Batteries.RBNode α} {c : Batteries.RBColor} {n : Nat} (h : t.Balanced c n) :
t.depth 2 * (t.size + 1).log2
theorem Batteries.RBNode.WF.depth_bound {α : Type u_1} {cmp : ααOrdering} {t : Batteries.RBNode α} (h : Batteries.RBNode.WF cmp t) :
t.depth 2 * (t.size + 1).log2

A well formed tree has t.depth ∈ O(log t.size), that is, it is well balanced. This justifies the O(log n) bounds on most searching operations of RBSet.