Red-black tree
Insert numbers into a tree with red and black nodes. See when recoloring is enough and when a rotation is needed.
The root is black. Two red nodes never occur consecutively. Every path from the root to an empty child has the same number of black nodes.
In this left-leaning variant, a red child sits on the left. Diamonds are red nodes and circles are black. A ↻ marks a rule currently being repaired.
Height stays O(log n). Searching or inserting among n keys takes O(log n) time.