Rebalancing deletion for AVL binary search trees #
Deletion follows the search path to the target key. A matching node with an empty right child is
replaced by its left child; otherwise its leftmost right-subtree key is detached via rebalancing
splitMin and promoted, with balance restoring the ±1 sibling-height invariant at every
ancestor along the root-to-detached-node path.
Unlike Cormen et al., Problem 13-3, which covers the AVL invariant, Fibonacci height
bound, balance, and insert, this module extends the same balance combinator to
successor-splice deletion so that AVLTree supports the full
Cslib.DataStructure.OrderedSet.spec interface including Op.delete and extractMin.
Main definitions #
splitMin: detach the minimum key of a nonempty subtree while rebalancing ancestors.glue: join the two children of a deleted node with rebalancing.erase: delete a key from an AVL tree while preservingValid.eraseVisits: internal-node visits along the search andsplitMinpath.
Main results #
elements_erase:elements (erase x t) = (elements t).erase xon ordered trees.valid_erase:erasepreserves full AVL validity (Ordered,HeightConsistent,Balanced).cachedHeight_erase_bounds: deletion shrinks height by at most1and never increases height.erase_eq_of_notMem: deleting an absent key from a valid AVL tree leaves the tree unchanged.searchVisits_le_eraseVisits,eraseVisits_le_cachedHeight: deletion pays at least the downward search visits and visits at mostt.cachedHeightpath nodes.
References #
Delete x from t, rebalancing ancestors along the search path.
erase preserves full AVL validity (Ordered, HeightConsistent, and Balanced).
Deletion shrinks cached height by at most 1 and never increases height.
Deleting an absent key from a valid AVL tree leaves the entire tree unchanged.
Internal-node visits of erase: the downward search path plus leftmost splitMin descent in
the matched node's right subtree. Rebalancing reads of O(1) off-path sibling/nephew cached
heights at visited ancestors are not counted separately.
Deletion pays for the downward search path and possibly a splitMin descent on top.
Deletion visits at most t.cachedHeight internal path nodes.