RedBlack Tree Rotations 832007 UMBC CMSC 341 RBTDiagrams
Red-Black Tree Rotations 8/3/2007 UMBC CMSC 341 RBTDiagrams
Red-Black Diagrams The diagrams which follow show the rotations and recoloring for each “case” for Bottom-Up Insertion, Top-Down Insertion and Bottom-Up Deletion. Bear in mind that each case has a left-right symmetrical twin which is not shown here. 8/3/2007 UMBC CMSC 341 RBTDiagrams 2
Bottom-Up Insertion Case 0 - X is the root Color it Black G Case 1 – U is Red U P X Recolor P, G, U Move X up to G Move to another case G U P X G Case 2 -Uncle is black. X and P are opposite children Recolor X and G S Case 3 – Uncle is Black X and P are both left (right) children X 8/3/2007 U P X Zig-Zag Rotation X S G S U P G P Rotate P around G Recolor P and G UMBC CMSC 341 RBTDiagrams G X S U 3
8/3/2007 UMBC CMSC 341 RBTDiagrams 4
Top Down Insertion Case 1 – P is Black P X Y Case 2 – P is red P and X are both left (right) X children Y P Recolor X, Y and Z X P Y G G U Recolor X, Y, Z, P, G S U X Rotate P around G G X S Z Y G P U S X Z Rotate X around P U P S S U X X Recolor X, Y, Z Z Z G Y 8/3/2007 P P Y Case 3 – P is red and P and X are opposite children P Z Y UMBC CMSC 341 RBTDiagrams Recolor X, G Rotate X around G G P S Y Z U 5
- Slides: 5