DSA II · Balance & rotations

AVL Rotation Lab

Start with an LL, RR, LR, or RL example, or generate a larger AVL tree. Step through search, insertion, or deletion; inspect balance factors bottom-up and watch each single rotation preserve the inorder sequence. Double rotations take two separate steps.

Begin prepares an operation. Step advances a comparison, structural update, balance check, or rotation. Reset replays the same operation. Build AVL and Generate random AVL create complete starting trees.

Current action

Inorder sequence

AVL tree

100%
Compared, checked, or rotated nodesPromoted node

Height of an empty subtree is −1; height of a leaf is 0 (height counts edges). BF = height(left) − height(right). Heights and balance factors are recomputed for each displayed state, including temporary imbalance.

Rotation reference

ImbalanceCondition at zRepair
LLBF(z) > 1; BF(left) ≥ 0Right rotation at z
RRBF(z) < −1; BF(right) ≤ 0Left rotation at z
LRBF(z) > 1; BF(left) < 0Left at left child, then right at z
RLBF(z) < −1; BF(right) > 0Right at right child, then left at z

Repair the lowest unbalanced node first. A zero child balance factor can occur during deletion and uses a single rotation. Deletion may require repairs at several ancestors. Duplicate keys are excluded in this lab.