Trees & SearchD3Phase 3self-balancingrotationsheight

AVL Rotations

Balance-factor-driven single and double rotation visual explanation.

Easy Explanation

AVL rotations rebalance a binary search tree after updates so lookups stay fast.

Visualizer
O(1)AVL Rotations
Deterministic AVL insertion playback with per-node height updates, imbalance detection, and explicit left/right rotations.

Sequence

0 inserts

Tree

0 nodes / h=0

Balancing

i:0 r:0

Updates

h:0 d:0

Ready

Press Play or Step to start execution.

Insert Sequence

n/a

Current Frame

empty

Final Output

empty

Provide insert values or randomize to generate a run.
currentrotation path
AVL Rotations Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
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
1.00xNo Run