Overview

Red-black trees are self-balancing binary search trees that guarantee O(lg n) worst-case time for all basic dynamic-set operations. By augmenting each node with a single color bit (red or black) and enforcing five structural properties, red-black trees ensure that no root-to-leaf path is more than twice as long as any other, keeping the tree approximately balanced. This chapter covers the red-black properties, rotations, and the intricate insertion and deletion fixup algorithms that maintain balance.

Key Concepts

  1. Every node is either red or black.

  2. The root is black.

  3. Every leaf (NIL) is black. (Leaves are sentinels, not key-bearing nodes.)

  4. If a node is red, both its children are black. (No two consecutive red nodes on any path.)

  5. For each node, all simple paths from that node to descendant leaves contain the same number of black nodes.

Algorithms and Techniques

Insertion: RB-INSERT and RB-INSERT-FIXUP