Академический Документы
Профессиональный Документы
Культура Документы
tree.
Named after their inventors, Adelson - Velskii
and Landis.
They were the first dynamically balanced trees
to be proposed.
Like red-black trees, they are not perfectly
balanced, but pairs of sub-trees differ in height
by at most 1
An AVL tree is a binary search tree which has the
following properties :
0 +1
26 72
-1
0 0 -1
25
38 63 94
0
0
3 0 0
37
47 78
Balance not ok
Find rebalancing case
-1 57
-1 26 +1 72
-1 3 0 37 0 47 0 78
0 1
0 26 +1 72
0 3 0 38 0 63 -1 94
0 1 0 25 0 37 0 47 0 78
-1 57
+1 26 +1 72
0 3 -1 38 0 63 -1 94
0 1 0 25 -1 37 0 47 0 78
0 30
+2 26 +1 72
0 3 -2 38 0 63 -1 94
0 1 0 25 -2 37 0 47 0 78
+ 30
1
0 32
+2 26 +1 72
0 3 -2 38 0 63 -1 94
0 1 0 25 -2 37 0 47 0 78
+ 30
Left Right Case 1
0 32
+2 26 +1 72
0 3 -2 38 0 63 -1 94
0 1 0 25 -2 37 0 78
0 47
-1 32
0 30
+1 26 +1 72
0 3 -1 38 0 63 -1 94
0 1 0 25 0 32 0 47 0 78
0 30 0 37
0 3 -2 38 0 63 -1 94
0 1 0 25 + 32 0 47 0 78
1
0 30 -1 37
Left Right Case
0 35
+2 26 +1 72
0 3 -2 38 0 63 -1 94
0 1 0 25 -2 37 0 47 0 78
0 32
0 30 0 35
-1 57
+1 26 +1 72
0 3 0 37 0 63 -1 94
0 1 0 25 0 32 +1 38 0 78
0 30 0 35 0 47
+1 26 +1 72
0 3 0 37 0 63 -1 94
0 1 0 25 0 32 +1 38 0 78
0 30 0 35 0 47
Exercise: insert 36