Red-Black trees
Introduction / Definition
A Red-Black tree is a self-balancing binary search tree whose nodes have red or black colors. Its color rules restrict how unbalanced the tree can become. Rotations and recoloring repair violations. Search, insertion, and deletion are O(log n) in the worst case.
Syntax / Structure / Formula
Root black; red nodes cannot have red children; equal black-height paths.
Detailed Explanation
After insertion or deletion, local transformations restore the coloring properties while preserving key order.
Example
Example: Two consecutive red nodes after insertion trigger a repair case.
Output / Result
The tree returns to a valid Red-Black state.
Important Points / Notes
- Maintains O(log n) operations.
- Rotations preserve in-order ordering.
Mini Practice Question
State two Red-Black tree properties.