An AVL tree is a binary search tree that stays balanced: for every node, the heights of its two subtrees differ by at most one. This balance factor keeps height at O(log n), guaranteeing O(log n) search, insert and delete. When an insertion violates the balance, rotations (left, right, left-right, right-left) restructure the tree to restore it.
AVL rebalancing rotationsBalance factor = height(left) − height(right) ∈ {−1, 0, +1}
Insert in the left-left case → single right rotation
Insert in the right-right case → single left rotation
Left-right and right-left cases → double rotations
Guaranteed height h ≤ 1.44 · log₂(n+2) − 1.328Why balance matters
Inserting 1, 2, 3, ... into a plain BST produces a degenerate chain of height n — search becomes O(n). AVL rotations keep the tree compact so search stays logarithmic.