LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

What problem does an AVL tree solve, and what rule does it enforce?

A plain binary search tree can degenerate into a chain of height $n$; an AVL tree forbids that with one rule: at every internal node, the heights of the two child subtrees differ by at most 1. That keeps the height in $O(\log n)$.

An AVL tree with its heights next to a tree that breaks the rule at the root

* Every node is checked, not just the root: one place where the children differ by 2 is enough to break the rule. *

Every operation on a binary search tree walks one path from the root, so it costs $O(h)$, where $h$ is the height. If the keys arrive in sorted order, each new key becomes the right child of the previous one and the tree is a linked list in disguise: $h = n - 1$, and search is no better than a linear scan: with a million keys, up to a million comparisons instead of about 20.

Adel'son-Vel'skii and Landis (1962) added a height-balance property to the search-tree rules:

for every internal node, the heights of its left and right subtree differ by at most 1.

A missing child counts as height $-1$ (a leaf has height 0), so a node with one leaf child and no other child is still fine. The rule compares heights, not node counts: the two subtrees of a node may hold very different numbers of nodes, as long as neither reaches more than one level deeper. The rule does not ask for a perfect tree. It tolerates some slack everywhere, which is what makes it cheap to maintain: the tree repairs itself with a few local rotations after an update, a self-organising tree.

How to check it by hand: compute the height of every node bottom-up (leaf 0, otherwise 1 + the larger child height), then compare the two child heights at each node.

Go deeper:

From Quiz: ADS / AVL Trees and Splay Trees | Updated: Nov 26, 2026