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
- Batteries.RBNode.nil.depth = 0
- (Batteries.RBNode.node c a v b).depth = max a.depth b.depth + 1
Instances For
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
Instances For
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
- Batteries.RBNode.depthUB Batteries.RBColor.red x✝ = 2 * x✝ + 1
- Batteries.RBNode.depthUB Batteries.RBColor.black x✝ = 2 * x✝
Instances For
theorem
Batteries.RBNode.WF.depth_bound
{α : Type u_1}
{cmp : α → α → Ordering}
{t : RBNode α}
(h : WF cmp t)
:
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.