Worked Examples: Red-Black Trees

These examples are designed to step through the logical process of applying the algorithmic concepts.

Example 1: Black Height
❓ Problem: Max height for bh(x)?
💡 Solution: $h \le 2 bh(x)$. Proof by properties.
Example 2: Rotation
❓ Problem: Right Rotate on x.
💡 Solution: x moves up, parent moves down-right. Subtrees shift.
Example 3: Double Red
❓ Problem: How to fix Red Parent + Red Uncle?
💡 Solution: Recolor both Black, Grandparent Red. Recurse up.
Example 4: Zig-Zag
❓ Problem: Fix Red Parent + Black Uncle (triangle)?
💡 Solution: Rotate to form line, then Rotate + Recolor.
Example 5: Performance
❓ Problem: Worst case Search?
💡 Solution: $2 \log_2 n$.
Example 6: vs AVL
❓ Problem: RB vs AVL?
💡 Solution: AVL more strictly balanced (faster search), RB faster insert/delete.