3.4.8 · D5Trees
Question bank — Red-Black tree — properties, rotations + recoloring (conceptual understanding)

True or false — justify
A Red-Black tree is always more balanced than an AVL tree of the same keys.
False — AVL is tighter (subtree heights differ by at most 1); RB only promises the longest path is at most twice the shortest, so an RB tree can be taller than the AVL tree for the same data.
Every Red-Black tree is a valid Binary Search Tree.
True — the coloring rules are layered on top of BST ordering; every operation (including rotations) preserves the left-<-node-<-right invariant, so RB is a BST first and colored second.
The root of a Red-Black tree can be red immediately after an insert, in the middle of the fixup loop.
True temporarily — Case 1 recoloring can paint the grandparent (which may be the root) red, but the fixup loop's final line forces the root back to black, so the finished tree always has a black root.
If a tree has no two reds in a row, it automatically satisfies all Red-Black properties.
False — "no red-red" is only property 4; you still need the equal-black-height property 5, the black root, and black
NIL leaves. A tree can be red-red-free yet have unequal black-heights.Coloring every node black gives a valid Red-Black tree.
False in general — an all-black coloring satisfies property 4 (no red-red) but property 5 fails whenever the tree's shape is unbalanced, since then two root-to-
NIL paths of different length have different black counts. It is valid only when the underlying shape already has every root-to-NIL path the same length (a perfectly balanced tree).Two Red-Black trees storing the same set of keys must have the same shape.
False — insertion order and the specific fixup cases taken can produce different (all valid) colorings and shapes; RB trees are not canonical for a key set.
A path with 3 black nodes and a path with 3 black nodes plus 2 reds can coexist in the same valid RB tree.
True — both paths have black-height 3, satisfying property 5; the reds don't count toward black-height, so extra reds on one path are allowed as long as no two touch.
Black-height counts the current node itself.
False (by this page's convention, stated in the notation box) — counts the black nodes on paths below down to
NIL, excluding ; the NIL leaves themselves are the black endpoints that get counted.Spot the error
"A new node is inserted black so it doesn't disturb the balance."
Error: new nodes are inserted red. A black insert adds one to the black-height of a single path, instantly breaking property 5 — the hardest property to repair. Red can only break the easy property 4.
"There's a red-red violation, so we must rotate."
Error: rotation is only for a black (or
NIL) uncle . If is red, plain recoloring (Case 1) fixes it and pushes the problem upward — rotating there would be wasted, over-corrective work."Uncle is red, so recolor parent black, uncle black, and leave the grandparent black."
Error: the grandparent must be flipped to red. Making both children black without reddening adds a black to every path through it, breaking equal black-heights; reddening keeps the counts balanced.
"After recoloring in the red-uncle case, we're done."
Error: just turned red and may now clash with its parent, so you must set the cursor and re-check upward. The problem floats up, it doesn't vanish.
"The uncle of a node is its parent's parent."
Error: that's the grandparent . The uncle is the parent 's sibling — 's other child.
"We ignore NIL nodes when computing black-height."
Error:
NIL sentinels are real black leaves and are exactly the endpoints property 5 counts paths to. Ignoring them breaks the whole black-height accounting."In the zig-zag (inner) case we rotate at the grandparent."
Error: the inner case (Case 2) rotates at the parent first, to straighten the –– line into the outer case (Case 3); only then does Case 3 rotate at the grandparent .
"A left rotation changes the sorted order of the keys."
Error: rotation is order-preserving. Before and after, holds; only the parent-child pointers change, never the in-order sequence.
Why questions
Why is a newly inserted node always colored red rather than black?
Because red can only violate the cheap property 4 (red-red), fixable locally by recolor/rotate, whereas black would violate property 5 (equal black-heights) on just one path — a global, expensive-to-repair break.
Why can the longest path never exceed twice the shortest?
Property 5 forces equal black nodes on every path, and property 4 forbids two reds in a row, so at most half a path's nodes are red; the reddest path is thus at most double the all-black path.
Why do Red-Black trees rotate less than AVL trees?
RB accepts a looser balance (2× spread), so many violations are fixed by cheap recoloring alone; a single insert needs at most a constant number of rotations, while AVL's strict height-1 rule triggers rotations more often. See AVL Tree and Tree Rotations.
Why do real libraries like std::map and TreeMap choose Red-Black over AVL?
Update-heavy workloads benefit from RB's fewer rotations per insert/delete; the slightly larger height barely affects lookup, and the constant rotation bound gives predictable performance. See std::map / TreeMap internals.
Why does forcing the root black at the very end never break any property?
Turning the root black adds exactly one black node to every root-to-
NIL path equally, so all black-heights rise together — property 5 stays satisfied and no red-red is introduced.Why does the red-uncle case (Case 1) guarantee the black counts stay balanced after recoloring?
We add one black on both of 's sides ( and both go black) and remove one from (it goes red), so every path through keeps its original black count.
Why does the black-uncle outer case (Case 3) terminate while the red-uncle case (Case 1) may loop?
Case 3 lifts a black node to the local subtree root, restoring both children's black-heights and killing the red-red in one shot with nothing pushed up; Case 1 only relocates the problem to , which may still conflict with its parent.
Why is a rotation described as ?
It rearranges a fixed, small number of pointers (a constant handful) regardless of tree size — no traversal or per-node work scales with . See Big-O Analysis.
Why can Red-Black trees be viewed as a disguise for 2-3-4 trees?
Each black node with its attached red children maps to a single 2-3-4 node (a 2-, 3-, or 4-node), so RB is a binary encoding of a perfectly-balanced 2-3-4 tree — which is why every RB path has equal black-height. See 2-3-4 Tree.
Edge cases
Can a Red-Black tree be a single node? What color is it?
Yes — that node is the root and must be black (property 2). Its two children are black
NIL sentinels, giving a valid black-height of 1.Is an empty tree a valid Red-Black tree?
Yes — the empty tree is just the
NIL sentinel, which is black by property 3; there are no nodes to violate any rule.What happens when the inserted node's parent is black?
Nothing to fix — a red under a black creates no red-red, black-heights are untouched, so the fixup loop never even starts.
When the uncle is NIL, is it treated as red or black?
Black —
NIL is always a black leaf, so a missing uncle triggers the black-uncle branch (Case 2/3, rotate-and-recolor), not the recolor-only Case 1.If a red node has only one real child and one NIL child, is that a red-red violation?
Only if the real child is red; the
NIL child is black and can never cause red-red. A red node with a black NIL on one side and a red data child on the other still violates property 4.Can the fixup loop climb all the way to the root?
Yes — repeated Case 1 recoloring can propagate up to the root; the loop then stops because the root has no parent, and the final step recolors the root black.
Does deleting a node ever require inserting a "double-black" placeholder concept?
Yes — deletion is trickier than insertion because removing a black node reduces one path's black count; the fix models the missing black as a temporary "double-black" that is pushed up or resolved via sibling recoloring/rotation until property 5 is restored.
What is the smallest black-height a tree of height can have?
About — since at most half the nodes on any path are red (property 4), the black nodes number at least , which is exactly the fact used to derive .