Why it matters

Red-black trees underlie most library ordered maps. Understanding enables informed use.

Advertisement

The architecture

Colors: red or black.

Invariants: root black; red has black children; equal black-heights all root-to-leaf paths.

Red-black rulesColorsred / blackInvariants5 rulesRotations + recoloringrestore after modsHeight ≤ 2 log(n+1); guaranteed O(log n) ops
RB tree properties.
Advertisement

How it works end to end

Insert: color new node red; fix violations via rotations + recoloring.

Delete: complex case analysis; rebalance from parent.

Use: Java TreeMap, C++ std::map, Linux CFS scheduler.