Presentation is loading. Please wait.

Presentation is loading. Please wait.

Red-Black Trees Acknowledgment Many thanks to “erm” from Purdue University for this very interesting way of presenting this course material. 1.

Similar presentations


Presentation on theme: "Red-Black Trees Acknowledgment Many thanks to “erm” from Purdue University for this very interesting way of presenting this course material. 1."— Presentation transcript:

1 Red-Black Trees Acknowledgment Many thanks to “erm” from Purdue University for this very interesting way of presenting this course material. 1

2 A red-black tree is a binary search tree with the following properties: edges are colored red or black no two consecutive red edges on any root-leaf path same number of black edges on any root-leaf path (  black height of the tree) edges connecting leaves are black Red-Black Tree 2

3 Correspondence between 2-3-4 and Red-Black trees Notice that red-black trees are just a way of representing 2-3-4 trees! 3

4 More Red-Black Tree Properties 4

5 Insertion into Red-Black Trees 1.Perform a standard search to find the leaf where the key should be added 2.Replace the leaf with an internal node with the new key 3.Color the incoming edge of the new node red 4. Add two new leaves, and color their incoming edges black 5.If the parent had an incoming red edge, we have two consecutive red edges! We must reorganize tree to remove that violation. What must be done depends on the sibling of the parent. 5

6 6

7 7

8 8

9 9

10 10

11 11

12 12

13 Insertion: an example 13 Start by inserting “REDSOX” into an empty tree

14 14

15 15

16 16

17 17

18 18

19 19

20 20

21 21


Download ppt "Red-Black Trees Acknowledgment Many thanks to “erm” from Purdue University for this very interesting way of presenting this course material. 1."

Similar presentations


Ads by Google