Maintain balance in AVL and red-black trees
8 steps · about 2 h 55 min · Intermediate
- See why unbalanced BSTs degrade to O(n) (guide, Runestone Academy, 20 min)
Derives balance factors and shows how sorted insertions ruin plain binary search tree performance.
- Master left and right rotations (reference, Wikipedia, 15 min)
Proves that local pointer rotations change subtree heights while preserving inorder key order.
- Learn the AVL height-balance invariant (reference, Wikipedia, 20 min)
Categorizes the four imbalance cases (LL, RR, LR, RL) and the exact rotations that restore balance.
- Step through AVL rotations interactively (interactive, University of San Francisco, 20 min)
Animates balance factors and double rotations as keys are inserted and deleted.
- Implement balance-factor updates in Python (tutorial, Runestone Academy, 25 min)
Shows how to propagate height changes upward and stop once a subtree's height stabilizes.
- Contrast AVL strictness with red-black invariants (reference, Wikipedia, 25 min)
Explains the five colour rules that bound longest-to-shortest path ratios with fewer rotations.
- Watch recolouring and rotations in a red-black tree (interactive, University of San Francisco, 20 min)
Makes uncle-colour cases visible so recolouring versus rotation decisions become intuitive.
- Unify red-black trees via 2-3 tree equivalence (guide, Princeton University, 30 min)
Presents left-leaning red-black trees as a compact, clean implementation of balanced 2-3 search trees.