Red-Black Example 1 Solution
These screen shots were taken from this
website. It's a Java applet and the
source code is freely available there.
Original tree: (2, 14, 11, 1, 7, 5, 8, 15)
Insert 4:
Uncle is red, so recolor trinode. X is now 7, Y is now 14. Y is BLACK, X is RIGHT,
so set X to 2 and rotate LEFT about new X (promote 7).
and rotate RIGHT about X's Grandparent (11) (promote 7 again)
and set Parent to Black and Grandparent to RED
Insert 6:
Insert 9:
Insert 10. Parent is RIGHT child, Uncle is BLACK (null), X is RIGHT,
so rotate LEFT about X's Grandparent (8), (promote X's parent, 9)
and set Parent to BLACK and (old) Grandparent to RED: