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
        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.

          Deletion visits at most t.height internal nodes.

          Unlike insertion, deletion never increases the height.