Documentation

Complexity.Algorithms.Lean.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 #

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

Instances For

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

    Instances For

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

      Instances For

        The detached key together with the remaining tree represents the original set.

        Gluing loses only the key of the deleted node.

        theorem Cslib.Algorithms.Lean.SearchTree.ordered_splitMin {α : Type u_1} [LinearOrder α] {a : α} {l r : BinaryTree α} (ht : Ordered (BinaryTree.node a l r)) :
        Ordered (splitMin a l r).2 ∧ ∀ y ∈ elements (splitMin a l r).2, (splitMin a l r).1 < y

        In an ordered tree the detached key is the least, and the remaining tree stays ordered.

        theorem Cslib.Algorithms.Lean.SearchTree.ordered_glue {α : Type u_1} [LinearOrder α] {a : α} {l r : BinaryTree α} (ht : Ordered (BinaryTree.node a l r)) :

        Gluing the subtrees of an ordered node yields an ordered tree.

        theorem Cslib.Algorithms.Lean.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.Algorithms.Lean.SearchTree.ordered_erase {α : Type u_1} [LinearOrder α] {t : BinaryTree α} (ht : Ordered t) (x : α) :

        The binary-search-tree invariant survives deletion.

        theorem Cslib.Algorithms.Lean.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.

        Instances For

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

          Unlike insertion, deletion never increases the height.