AVL Tree Visualizer
Interactive visualization of AVL Tree operations (Self-Balancing Binary Search Tree) with animated rotations.
📚 How AVL Tree Balancing Works
Try this: Insert values 10, 20, 30 and watch the automatic rotation! The tree will
rotate to keep balance.
🔄 Four Types of Rotations:
Before (Left-Left Case)
30
/
20
/
10
30
/
20
/
10
➜
After (Right Rotation)
20
/ \
10 30
20
/ \
10 30
- 1 Insert Node: New node is added following BST property (left if smaller, right if larger)
- 2 Update Heights: All ancestor heights are recalculated from the inserted node upward
- 3 Check Balance: Balance factor = left height - right height (must be -1, 0, or 1)
-
4
Apply Rotation: If balance factor is outside [-1, 1], perform appropriate rotation:
- Left-Left: Single Right Rotation
- Right-Right: Single Left Rotation
- Left-Right: Left rotation on left child, then Right rotation on parent
- Right-Left: Right rotation on right child, then Left rotation on parent
- 5 Watch Animation: Nodes smoothly transition to their new positions with 0.8s animation
✨ Visual Features:
- Smooth Animations: Nodes move with cubic-bezier easing for natural motion
- Appear Effect: New nodes scale up from zero with fade-in animation
- Auto-Center: Tree automatically centers in the container
- Balanced Layout: Horizontal spacing adapts to tree depth
About AVL Trees
An AVL tree is a self-balancing binary search tree named after inventors Adelson-Velsky and Landis. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property.
Key Features:
- Self-Balancing: Automatically maintains O(log n) height through rotations
- Guaranteed Performance: Search, insertion, and deletion all O(log n) time
- Balance Factor: Each node stores height information for efficient balancing
- Four Rotation Types: Handles all imbalance cases with single or double rotations
Common Use Cases:
- Database indexing where balanced search is critical
- Memory allocation systems
- Priority queues with frequent updates
- Applications requiring guaranteed O(log n) operations