RB Insert: Case 1
if (y->color == RED)
x->p->color = BLACK;
y->color = BLACK;
x->p->p->color = RED;
x = x->p->p;
Case 1: “uncle” is red
In figures below, all ?’s are equal-black-height subtrees
C
A
D
?
B
?
?
?
?
C
A
D
?
B
?
?
?
?
x
y
new x
Change colors of some nodes, preserving #4: all downward paths have equal b.h.
The while loop now continues with x’s grandparent as the new x
case 1
Previous slide
Next slide
Back to first slide
View graphic version