Data Structures: Sohail Aslam
Data Structures: Sohail Aslam
Lecture 21
Sohail Aslam
1
AVL Tree Building Example
2
AVL Tree Building Example
Insert(3)
2
1 3
3
AVL Tree Building Example
Insert(4)
2
1 3
4
AVL Tree Building Example
Insert(5)
2
1 3 -2
5
AVL Tree Building Example
Insert(5)
2
1 4
3 5
6
AVL Tree Building Example
Insert(6)
2 -2
1 4
3 5
7
AVL Tree Building Example
Insert(6)
4
2 5
1 3 6
8
AVL Tree Building Example
Insert(7)
4
2 5 -2
1 3 6
9
AVL Tree Building Example
Insert(7)
4
2 6
1 3 5 7
10
AVL Tree Building Example
Insert(16)
4
2 6
1 3 5 7
16
11
AVL Tree Building Example
Insert(15)
4
2 6
1 3 5 7 -2
16
15
12
AVL Tree Building Example
Insert(15)
4
2 6
1 3 5 16 -2
15
13
Cases for Rotation
14
Cases for Rotation
15
Cases for Rotation
16
Cases for Rotation
17
Cases for Rotation
k1 k2
Z Level n-2 X
X Y Level n-1 Y Z
new
Level n
new
18
Cases for Rotation
k2 k1
X Level n-2
Z
Y Level n-1
X Y
Z
Level n
19
Cases for Rotation
k1 k2
Z Level n-2 X
X Y Level n-1 Y Z
Level n
new new
20