Why it matters

RB is most common balanced BST in libs. Understanding shapes design.

Advertisement

The architecture

Red or black nodes.

No two reds adjacent.

Equal black-height on paths.

Rotations + recoloring.

Red-Black treeColor nodesred / blackInvariantsno adjacent redsFix on insert/delrotate + recolorJava TreeMap + TreeSet use RB; balanced insert cost
Red-Black.
Advertisement

How it works end to end

Insert: fix violations up.

Amortized O(1) rotations.

Delete: also fix violations.

3.44 log n comparisons max.