blob: 9036d2701a8829d554dd558f4cb3f72df5c23e2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
Illustrate that the nodes of any AVL tree T can be
colored "red" and "black" so that T becomes a
red-black tree.
```plaintext
AVL Tree Red-Black Tree
(20:3) (20:b)
/ \ --> / \
(15:2) (30:2) (15:b) (30:b)
/ \ \ / \ \
(10:1) (17:1) (35:1) (10:r) (17:r) (35:r)
* perform pre order traversal
* assign colour of Red/Black node based on height of each AVL node
Step 1:
(20:b)
Step 2:
(20:b)
/
(15:b)
Step 3:
(20:b)
/
(15:b)
/
(10:r)
Step 4:
(20:b)
/
(15:b)
/ \
(10:r) (17:r)
Step 5:
(20:b)
/ \
(15:b) (30:b)
/ \
(10:r) (17:r)
Step 6:
(20:b)
/ \
(15:b) (30:b)
/ \ \
(10:r) (17:r) (35:r)
```
|