Fix a violation
Warm-up · Multiple choice · about 4 min
A red-black tree holds 10 (black) and 5 (red). Insert 3. It becomes a red left child of 5, so 5 and 3 are both red. The uncle of 3 is empty, which counts as black. Which tree is the correct result?
Example 1
Input:
insert 3
Output:
one rotation
Red 3 under red 5 with an empty uncle.
Learn the idea first: Red-black trees, a visual lesson.
More Red-black trees problems
- Valid colorings Standard
- Black height Standard