Red-Black Trees

What is it?

A red-black tree is a self-balancing binary search tree. Every node is colored red or black, and a few simple rules keep the tree balanced so that search, insert and delete all run in O(log n) time.

Example red-black tree with root 13

The rules

  1. Every node is either red or black.
  2. The root is black.
  3. A red node never has a red child.
  4. Every path from a node to its null descendants has the same number of black nodes.

Learn more

Read more on Wikipedia.