Skip to content

fix: correct right-heavy AVL deletion rotations - #1591

Open
tianrking wants to merge 1 commit into
TheAlgorithms:masterfrom
tianrking:codex/fix-avl-deletion-rotations
Open

tianrking wants to merge 1 commit into
TheAlgorithms:masterfrom
tianrking:codex/fix-avl-deletion-rotations

Conversation

@tianrking

Copy link
Copy Markdown

Description of Change

Fix the right-heavy rebalancing conditions in AVL deletion. When the right child has balance -1, deletion currently selects a right-left rotation; when its balance is +1, deletion selects a single left rotation. These choices are reversed. For example, inserting 2, 1, 4, 5 and deleting 1 selects a rotation whose required child is absent, while inserting 2, 1, 4, 3 and deleting 1 leaves the tree unbalanced.

Use a single left rotation for right-child balance <= 0 and a right-left rotation for balance > 0. Add self-tests before the existing interactive example: six deletion rotation cases, sixteen deterministic insertion/deletion permutations, duplicate and missing-key operations, and signed key boundaries. Each mutation checks BST ordering, actual versus stored height, AVL balance, and the expected node set/count.

References

Validation on a public fork using standard Ubuntu 24.04 runners:

  • Original behavior: two reproducible failures and four passing controls with GNU 13.3, C11, and active assertions; ASan/UBSan confirms the incorrect rotation.
  • Exact final commit validation: built-in self-tests and all six standalone cases, ASan/UBSan, full Debug CMake build, and Clang 18 format/static checks. The static-check helper omits the obsolete AnalyzeTemporaryDtors configuration field; the repository's configured checks and warnings-as-errors remain enabled.

The validation workflow and probe are separate from this PR.

Checklist

  • Added description of change
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Searched previous suggestions before making a new one
  • I acknowledge that all my contributions will be made under the project's license

Notes: Existing AVL deletion now chooses the correct single or double rotation for a right-heavy subtree.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant