AVL Tree

AVL Tree, named after its inventors Adelson-Velskii and Landis, is a self-balancing binary search tree that maintains the height balance property (in addition to the BST order property) using structural rotations.

The insertion and deletion operations for AVL trees begin similarly to the corresponding operations for (regular) binary search trees. It then performs post-processing structural rotations to restore the balance of any portions of the tree that are adversely affected by the insertion/removal.

Insertion

Removal

Recommendation: Implement insertion/removal (with structural rotations) recursively!

For the implementation of AVL Tree, you must store the height of each node.

As you insert/remove, you must travel upward towards the root to update the height of ancestors.

Resources