Presentation is loading. Please wait.

Presentation is loading. Please wait.

Red Black Tree Prof Amir Geva Netzer Eitan.

Similar presentations


Presentation on theme: "Red Black Tree Prof Amir Geva Netzer Eitan."— Presentation transcript:

1 Red Black Tree Prof Amir Geva Netzer Eitan

2 Properties Every node is either red or black
Every son of a leaf is black (A.K.A null is black) Son of a red node cant be red (A.K.A no two reds in a row) For every track from the root to a leaf contains the same number of black node on the way

3 Rotates

4 Insert Add new like normal binary search tree Paint new node as red
If new node father is black then red black tree properties are held See options ahead

5 Notation X: new node F: father(X) G: father(F) (if exist)
U: son(G) s.t U~=F (if exist) F color is red G color is black

6 A) F is root F F X X

7 B) U is red G G U U F F X X

8 (mirror) G G U U F X X F

9 (mirror) F G U F X G U X

10 Insert summary If After inserting if is G painted Red continue processes up the tree Else Done Time complexity

11 Delete If delete node has both sons replace delete node with minimum node in right sub-tree (new delete node has only one son if any) If delete node is red then red black tree properties are held If delete node is black and its son is red, paint its son black and delete node Both delete node are black

12 Notation Y: node to delete X: son(Y) W: brother of X AFTER we delete Y
F: father of X and W AFTER we delete Y A,B have sub trees (the have sons) X and Y are black

13 A) W is red W F B W F X B A A X

14 B) W is black and F is red F F W W X X B B A A

15 C) W, F and the sons of W are black
X X B B A A

16 D) W is black and it’s a right child of its father and has left red son
X W X W B A B

17 (solution for D) F W W X A F A B B X

18 Delete summary If After deletion processes continue up or down the tree *circled node is the new “X” in other cases Else Done Time complexity


Download ppt "Red Black Tree Prof Amir Geva Netzer Eitan."

Similar presentations


Ads by Google