← All Tools

AVL Tree Visualizer

An AVL tree is a binary search tree that re-balances itself after every insert and delete so the heights of the left and right subtrees of every node differ by at most one. When that invariant breaks, exactly one of four rotation patterns (LL, LR, RL, RR) restores it โ€” and you can watch each one fire live below.

Tree statistics

Nodes0
Height0
Worst-case h for BST0
Optimal h (โŒˆlogโ‚‚ nโŒ‰)0
Rotations so far0

Operation log

Traversals

in-order:โ€”
pre-order:โ€”
post-order:โ€”
level-order:โ€”

Each node shows key in the centre, height (h) above-right, and balance factor (bf) below-right.
imbalanced (|bf| โ‰ฅ 2)   rotated this step   search hit

The four rotation cases

Imbalance is named by where the new key landed relative to the unbalanced ancestor's two-edge ladder:

Because AVL re-balances eagerly, lookups are guaranteed O(log n) โ€” the height is bounded by roughly 1.44 ยท logโ‚‚(n + 2). Compare this to inserting 1, 2, 3, 4, 5 into a plain BST, which would degenerate to a height-5 linked list; click the worst-case button above to watch AVL keep that flat.