70 likes | 202 Vues
This guide provides a comprehensive walkthrough for inserting and deleting nodes in a Red-Black Tree. Starting with an empty tree, you'll learn how to insert values like 2, 1, 4, 5, 9, 3, 6, and 7 while adhering to Red-Black Tree properties. We will also go through the process of deleting nodes, specifically 90, 80, and 70, and demonstrate the subsequent rotations and recoloring needed to maintain tree balance. This exercise is essential for understanding Red-Black Trees in data structures and algorithms.
E N D
11 Insert 4 into this R-B Tree 14 2 15 1 7 5 8 Red node Black node UMBC CSMC 341 Red-Black-Trees-1
Insertion Practice Insert the values 2, 1, 4, 5, 9, 3, 6, 7 into an initially empty Red-Black Tree UMBC CSMC 341 Red-Black-Trees-1
case 1 2 2 2 2 1 1 4 1 4 1 4 5 5 case 2 case 3 2 2 2 1 4 1 5 1 5 5 2 2 4 9 4 9 2 9 3 1 5 1 5 1 5 4 9 4 7 4 9 3 3 6 6 9 3 6 7 Constructing a RB tree by inserting 2, 1, 4, 5, 9, 3, 6, 7 2
65 50 80 10 70 90 60 62 Perform the following deletions, in the order specified Delete 90, Delete 80, Delete 70 UMBC CSMC 341 Red-Black-Trees-2
case 1 50 65 65 rotate 50 about 65 Recolor 50 and 65 50 70 10 65 50 V+ 60 60 10 V+ 60 10 case 3 case 4 62 62 62 50 Rotate62 about 65 recolor 62, 65 and 60 Rotate62 about 60 recolor 62 and 60 10 65 62 V+ 60 50 10 62 60 65