Professional Documents
Culture Documents
AVL Trees: Presentation For Use With The Textbook, by M. T. Goodrich and R. Tamassia, Wiley, 2015
AVL Trees: Presentation For Use With The Textbook, by M. T. Goodrich and R. Tamassia, Wiley, 2015
AVL Trees
6
v
3 8
z
4
4 n(1)
c=z
17 78 17 78
a=y
32 50 88 32 50 88
48 62 48 62
b=x
54
w
before insertion
after insertion
© 2015 Goodrich and Tamassia AVL Trees 4
Trinode Restructuring
Let (a,b,c) be the inorder listing of x, y, z
Perform the rotations needed to make b the topmost node of the three
Single rotation Double rotation around
around b a=z
c and a
a=z
c=y
b=y
T0
T0
c=x b=x
T3
T1 b=y b=x
T2 T3 T1 T2
a=z c=x a=z c=y
T0 T1 T2 T3 T0 T1 T2 T3
54 88
image, or the image may
T2
T0 T1 T3
© 2015 Goodrich and Tamassia AVL Trees 6
Restructuring (as Single Rotations)
Single Rotations:
a =z single rotation b =y
b =y a =z c=x
c=x
T0 T3
T1 T3 T0 T1 T2
T2
T3 T3
T0 T2 T2 T1 T0
T1
© 2015 Goodrich and Tamassia AVL Trees 7
Restructuring (as Double Rotations)
double rotations:
T0 T2
T2 T3 T0 T1 T3
T1
T0 T2
T3 T2 T3 T1 T0
T1
© 2015 Goodrich and Tamassia AVL Trees 8
Pseudo-code
Insertion.
17 62 17 62
32 50 78 50 78
48 54 88 48 54 88
44 78
w 17 62 b=y
17 50 88
50 78 c=x
48 54
48 54 88