Professional Documents
Culture Documents
AVL Trees
6
z
4
AVL Trees
n(2)
32
1
88
50
1
48
62
AVL Trees
n(1)
Insertion
Insertion is as in a binary search tree
Always done by expanding an external node.
Example:
44
44
17
78
17
78
c=z
a=y
32
50
48
n(h) > 2n(h-2), n(h) > 4n(h-4), n(h) > 8n(n-6), (by induction),
n(h) > 2in(h-2i)
88
62
32
50
88
48
62
b=x
54
3
78
17
4
44
before insertion
3
after insertion
AVL Trees
Trinode Restructuring
5
44
17
3
1
32
a=z
c=y
b=y
unbalanced...
T1
a=z
T3
T2
44
4
3
17
b=x
1
32
T2
c=x
a=z
c=y
...balanced
x
z6
62
2 y
3
50
78
54
48
88
T2
T2
T1
T0
T3
T0
T1
AVL Trees
T3
T2
5
Restructuring
(as Single Rotations)
b=y
single rotation
b=y
double rotation
a=z
a=z
c=x
c=y
c=x
T3
T1
b=x
a=z
c=y
b=x
T0
T3
T0
T1
T0
T2
T3
T2
T2
T0
T2
T1
T3
T1
double rotation
c=z
c=z
a=x
T3
T3
T2
T2
AVL Trees
T1
c=z
b=x
c=z
a=x
T3
b=x
a=y
a=y
b=y
single rotation
b=y
T1
double rotations:
a=z
T0
T0
AVL Trees
Restructuring
(as Double Rotations)
Single Rotations:
T1
2
T3
T1
88
T1
b=y
T3
62
T0
b=x
c=x
54
T0
T0
T2
48
7
1
50
64
78
2y
a=z
T0
T2
T0
T3
T2
T1
T0
T1
7
AVL Trees
T3
Removal
62
32
17
50
48
62
78
50
88
54
before deletion of 32
2004 Goodrich, Tamassia
48
78
54
48
after deletion
AVL Trees
AVL Trees
11
c=x
78
54
44
b=y
62
50
17
88
17
50
48
88
AVL Trees
78
88
54
10