โ Back to the trees page
Self-Balancing Trees (AVL / Red-Black)
BSTs that rotate on write to keep height O(log n) no matter the insertion order. The fix for the sorted-input worst case.
What to know
- AVL balances harder (height diff โค 1): faster reads, more rotation work on writes.
- Red-black relaxes balance for cheaper writes โ the standard library default.
- Full mechanics live in the Red-Black Trees deep dive.
In the wild: C++ std::map, Java TreeMap, Linux CFS scheduler, epoll timers.
Algorithms to reach for
Rotations (LL/RR/LR/RL)
O(1) eachLocal O(1) rebalancing after insert/delete
Guaranteed O(log n) ops
O(log n)Ordered map/set without degeneration
Practice problems โ with full guides
Each problem has its own page: progressive hints, how to approach it, and the full solution.