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 #
splitMin: detach the leftmost key of a nonempty tree.glue: join the two subtrees of a deleted node.erase: delete a key.eraseVisits: internal-node visits of deletion, in the model of the companion cost module.
Main results #
elements_erase,ordered_erase: deletion has set semantics and preserves the invariant.erase_eq_of_notMem: deleting an absent key preserves the entire tree.searchVisits_le_eraseVisits: deletion walks the search path ofcontainsandinsert, and then at most the left spine of the matched node's right subtree (minimumVisits).eraseVisits_le_height,height_erase_le: deletion visits at most the initial height and never increases the height.
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.
In an ordered tree the detached key is the least, and the remaining tree stays ordered.
Gluing the subtrees of an ordered node yields an ordered tree.
Deletion removes exactly the requested key, even when it was absent.
The binary-search-tree invariant survives deletion.
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.