AVL Insert with Rebalancing
Insert as a BST, walk back up updating heights, and rotate the first unbalanced node.
Decision · step 6 of 41AVL Tree: A longer mixed sequence
At 50: left height 1, right height 0, balance 1. Within one, so it stays.
What you will see
Insertion path replays upward; balance factors update; the offending node rotates.
Cost
| Best | O(log n) |
|---|---|
| Average | O(log n) |
| Worst | O(log n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.
Screen readers: Nodes announce value, left child and right child; each step announces the comparison and the direction taken or the structural change.
Reduced motion: Focus jumps node to node with a static ring; rotations become a crossfade between the two layouts.
Taught by the same lesson
AVL Tree covers these too, in the same run.