The Red-Black Rules
As mentioned, a red-black tree consists of nodes that are either red or black. There’s no way around this; each node must choose a side. You can’t have a node that has no color at all, or a node that is both red and black, or a node that prefers to be mustard yellow. Each node is either red or black, period.
However, not every tree that consists of red and black nodes is deemed a valid red-black tree. There are two major rules, which I call “The Red-Black Rules,” that a tree must adhere to for it to be admitted into the official red-black tree club:
-
The Black Height Rule: Each path from the root node to the bottom of the tree must contain the same number of black nodes.
-
The Red Enemies Rule: A parent and child cannot both ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access