Presentation is loading. Please wait.

Presentation is loading. Please wait.

CO4301 – Advanced Games Development Week 5 Walkthrough of Red-Black Tree Insertion Gareth Bellaby.

Similar presentations


Presentation on theme: "CO4301 – Advanced Games Development Week 5 Walkthrough of Red-Black Tree Insertion Gareth Bellaby."— Presentation transcript:

1 CO4301 – Advanced Games Development Week 5 Walkthrough of Red-Black Tree Insertion
Gareth Bellaby

2 Insert 40 Root, black 40

3 Insert 20 Parent is black No change 40 20

4 Insert 45 Parent is black No change 40 20 45

5 Insert 50 Parent is red Uncle is red 40 20 45 50

6 Colour uncle and parent black
Colour node and grandparent red Propagate change in rest of tree 40 20 45 50

7 Insert 43 Parent black No change 40 20 45 43 50

8 Insert 41 Parent red Uncle red 40 20 45 43 50 41

9 Colour uncle and parent black
Colour node and grandparent red Propagate change in rest of tree (no further changes) 40 20 45 43 50 41

10 Insert 42 Parent red Uncle black N is a right child Left rotation on P
40 20 45 G 43 50 U 41 P N is a right child Left rotation on P N 42

11 Effect of left rotation on P
40 20 45 43 50 42 Effect of left rotation on P 41

12 Relabel N and P Uncle is black N is left child Right rotation on G G U
40 20 45 G 43 50 U P 42 N is left child Right rotation on G 41 N

13 Effect of right rotation on G
40 20 45 42 50 P 41 N 43 G Effect of right rotation on G U

14 40 20 45 42 50 P 41 43 G Swap colours of P and G

15 The tree is still height balanced.
40 20 45 42 50 Examine the tree The tree is still height balanced. The number of black nodes is identical for every path to a leaf. 41 43 The values are sort order


Download ppt "CO4301 – Advanced Games Development Week 5 Walkthrough of Red-Black Tree Insertion Gareth Bellaby."

Similar presentations


Ads by Google