Download presentation
Presentation is loading. Please wait.
1
Red-Black Tree Rotations
2
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
3
Bottom-Up Insertion Case 0 - X is the root Color it Black
G G Recolor P, G, U Move X up to G Move to another case Case 1 – U is Red U U P P X Case 2 -Uncle is black. X and P are opposite children G P U X X Zig-Zag Rotation G P Recolor X and G S S U Case 3 – Uncle is Black X and P are both left (right) children G P U P Rotate P around G G X X Recolor P and G S U S 8/3/2007 UMBC CMSC 341 RBTDiagrams
4
8/3/2007 UMBC CMSC 341 RBTDiagrams
5
Top Down Insertion Case 1 – P is Black Recolor X, Y and Z
G Case 2 – P is red and P and X are both left (right) children G P P U Recolor X, Y, Z, P, G P U Rotate P around G G X X S X S Y Z Y Z S U Y Z G X Case 3 – P is red and P and X are opposite children G Recolor X,Y,Z X U G P U Recolor X, G P Rotate X around P P Z Rotate X around G S X S S Y Z U Y Y Z 8/3/2007 UMBC CMSC 341 RBTDiagrams
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.