Documentation

CslibFrontier.DataStructure.SearchTree.Erase

Deletion from unbalanced binary search trees #

Deletion follows the search path to the key. A matching node with an empty right subtree is replaced by its left subtree; otherwise its key is replaced by the leftmost key of the right subtree, which is detached from there. This is the successor-splicing deletion of Cormen et al., Chapter 12, except that a node with an empty left subtree is also rebuilt around its successor rather than replaced by its right subtree. Deleting an absent key leaves the tree unchanged.

Main definitions #

Main results #

References #

def Cslib.DataStructure.SearchTree.splitMin {α : Type u_1} (a : α) :
BinaryTree α → BinaryTree α → α × BinaryTree α

Detach the leftmost key of the nonempty tree .node a l r, returning it with the rest.

Join the subtrees of a deleted node, promoting the leftmost key of the right subtree.

Delete x along its search path; a matching node is replaced by glue of its subtrees.

theorem Cslib.DataStructure.SearchTree.elements_erase {α : Type u_1} [LinearOrder α] {t : BinaryTree α} (ht : Ordered t) (x : α) :

Deletion removes exactly the requested key, even when it was absent.

theorem Cslib.DataStructure.SearchTree.ordered_erase {α : Type u_1} [LinearOrder α] {t : BinaryTree α} (ht : Ordered t) (x : α) :

The binary-search-tree invariant survives deletion.

theorem Cslib.DataStructure.SearchTree.erase_eq_of_notMem {α : Type u_1} [LinearOrder α] {t : BinaryTree α} {x : α} (hx : x ∉ elements t) :
erase x t = t

Deleting an absent key preserves the entire tree, not just its represented set.

Internal-node visits of deletion: the search path, then leftmost descent in the right subtree of a matching node.

Deletion pays for the full search path and possibly a successor descent on top.

Deletion visits at most t.height internal nodes.

Unlike insertion, deletion never increases the height.