AlgoThrive
← All tree operations

AVL Rotation

ComparingInsertedUnbalancedRotating

binary search tree

left is smaller, right is larger

10
20
30

pseudocode

balance(node) = height(node.right) - height(node.left)
if |balance| > 1: node is unbalanced
(LL/RR: single rotation, LR/RL: rotate child first)
if the child leans the opposite way: rotate the child first
rotateLeft/rotateRight(node): pivot takes node's place
reattach pivot where node used to be

Frame 1 / 4

Starting tree

3 values inserted

4

39 unique integers, 199 each — inserted in order to build the starting tree.