Flow Chart of Red Black tree: 24

advertisement
Flow Chart of Red Black tree:
24
Examples of Insertions in Red-Black Tree
Given the following red-black tree, we will make a number of insertions
Adding 46 creates a red-red pair which can be corrected with a single rotation
Case 1, because parent is red and uncle is black, the sol. Rotate 42 to the left and recolor
25
Similarly, adding 5 requires a single rotation
Which again, does not require any additional work
Adding 10 allows us to simply swap the color of the grand parent and the parent and the parent’s
sibling
Case 2, sol. recolor
26
Adding 90 again requires us to swap the colors of the grandparent and its two children
27
Inserting 95 requires a single rotation
Case 1, because parent is red and uncle is black, the sol. Rotate 90 to the left and recolor
Adding 99 requires us to swap the colors of its grandparent and the grandparent’s children
28
Case 2, sol. recolor
This causes another red-red child-parent conflict between 85 and 90 which must be fixed, again
by swapping colors.
This results in another red-red parent-child conflict, this time, requiring a recolor
29
Case 1, because parent is red and uncle is black, the sol. Rotate 55 to the left and recolor
30
Download