80 likes | 357 Views
Red-Black Trees (Bayer, Guibas and Sedgewick). 26. RBT example:. 41. 17. 30. 47. 14. 21. 10. 28. 38. 16. 19. 23. 35. 39. 20. 7. 12. 15. 3. Red-Black Trees (Bayer, Guibas and Sedgewick). 2. 26. Black-heights:. 41. 1. 17. 2. 30. 47. 1. 0. 14. 1. 21. 1. 10. 28.
E N D
Red-Black Trees(Bayer, Guibas and Sedgewick) 26 RBT example: 41 17 30 47 14 21 10 28 38 16 19 23 35 39 20 7 12 15 3
Red-Black Trees(Bayer, Guibas and Sedgewick) 2 26 Black-heights: 41 1 17 2 30 47 1 0 14 1 21 1 10 28 38 1 0 0 16 19 23 0 0 0 35 39 0 0 20 0 7 12 15 0 0 0 Black-height of tree = black-height of root (2) 3 0
RBT Violation Fixes Case 1: c c Color flip d b d b a a Color flip fixes or moves violation towards the root.
RBT Violation Fixes Case 2: c c Color flip d b d b a a Color flip fixes or moves violation towards the root.
RBT Violation Fixes Case 3: c c Left Rotation d d b a Rest of Tree b a Rest of Tree Rest of Tree Rest of Tree Rest of Tree Rest of Tree Converted to Case 4
RBT Violation Fixes Case 4: c b Right Rotation d b c a a d Rest of Tree Rest of Tree Rest of Tree Rest of Tree Rest of Tree Rest of Tree Now re-color Nodes b and c.
RBT Violation Fixes Case 4: b b Color flip c c a a Rest of Tree d d Rest of Tree Rest of Tree Rest of Tree Rest of Tree Rest of Tree RBT violation is removed (see next slide).
RBT Violation Fixes Case 4: c b d b c a Rest of Tree Rest of Tree Rest of Tree a d Rest of Tree Rest of Tree Rest of Tree RBT structure is restored.