Balance-factor-driven single and double rotation visual explanation.
Easy Explanation
AVL rotations rebalance a binary search tree after updates so lookups stay fast.
Sequence
0 inserts
Tree
0 nodes / h=0
Balancing
i:0 r:0
Updates
h:0 d:0
Press Play or Step to start execution.
Insert Sequence
n/a
Current Frame
empty
Final Output
empty
function rebalance(node):
updateHeight(node)
balance <- height(node.left) - height(node.right)
if balance > 1:
if height(node.left.left) < height(node.left.right):
node.left <- rotateLeft(node.left)
return rotateRight(node)
if balance < -1:
if height(node.right.right) < height(node.right.left):
node.right <- rotateRight(node.right)
return rotateLeft(node)
return node