ALV TREE
Presented by: Amin Ullah
Amjad Husssain
Qazi Musa
Content
• Introduction
• Balance factor
• Properties
• Operation
Rotation
Insertion
Searching
Deletion
Inventors
AVL is named after two soviet inventors
• Adelson-Velsky
• Landis
• It is often compared with
RED black trees
• AVL trees are faster than red–
black trees because they are more
Strictly balanced
Introduction
• AVL tree is a self balancing binary search tree
• It was the first such data structure to be invented
• First dynamically balanced tree to be proposed
Binary Search Tree
50
40
30 45 7055
60
O(log n)
AVL tree
Balance Factor
50
5545
40
30
60
70
O(log n)
50
40
30
20
60
Just like leaner search
O(n)
Rotation
Insertion
• Presenting by:
Qazi Musa
For a tree to be balance, the value has to be only
-1, 0, 1
Node Height
1 0
5 0
6 0
10 0
13 -1
17 0
Un balance tree
Node Height
1 0
5 0
6 0
10 -1
13 -2
17 1
16 0
Insertion
4 possible situations to insert in a tree
Re-balancing a tree using rotations
4 possible rotation
1. LL Rotation
2. RR Rotation
3. LR Rotation
4. RL Rotation
Insertion
• 55, 66, 77, 15, 11, 32, 22, 35, 25 LL Rotation
-2
R
R
55
66
77
RR Rotation
+2
1st unbalancing +2
L
L
66
55 77
15
11
RR Rotation
66
15 77
55
11
LR Rotation
+2
L
R
66
15 77
55
11
33
L R Rotation
L
66
55 77
11
15
33
L R Rotation
55
77
66
11
15
33
RL Rotation
+2
-2
R
L
55
77
66
11
15
33
22
25
35
RL Rotation
R
55
77
66
11
15
22
33
25 35
RL Rotation
55
77
66
15
22
33
35
25
11
Searching
Deletion
• Presenting by:
• Amjad Hussain Qashqarien
Deletion in AVL tree:
• Same as the they deletion in binary tree.
• We have to fallow the three conditions of binary search tree
• If a node have no child's(leaf node)
• If a node have one child
• If a node have two child's
• But in AVL tree we have to balance the tree again after deleting a
node, if the balance factor of a node effect.
Searching in AVL tree:
• Same as binary tree.
• But less time cost.
• run time O(logn).
Comparison
• A binary search tree is a binary tree where, for each node, its left
subtree contains only nodes with lesser values and its right subtree
contains only nodes with greater values. That’s it.
• An AVL tree construct ensure the balance of the tree at every insert
operation and deletion operation.in all other respects it’s a binary
search tree.
• Binary search tree running time O(n).
• AVL tree running time O(logn).
Thanks

Algorithm presentation