A BST where height of two subtrees differs at most one. Permitted balance factors for any node are 0,1 and -1. Balance factor of any node can be computed by subtracting the height of right subtree from height of left subtree.
• Insertion, deletion and searching can be performed in O(logn).• Height <= 1.44 * (log n) where is n is number of nodes
AVL Tree Example:
• Insert 14, 17, 11, 7, 53, 4, 13 into an empty AVL tree
14
1711
7 53
4
AVL Tree Example:
• Insert 14, 17, 11, 7, 53, 4, 13 into an empty AVL tree
14
177
4 5311
13
AVL Tree Example:
• Now insert 12
14
177
4 5311
13
12
AVL Tree Example:
• Now insert 12
14
177
4 5311
12
13
AVL Tree Example:
• Now the AVL tree is balanced.
14
177
4 5312
1311
AVL Tree Example:
• Now insert 8
14
177
4 5312
1311
8
AVL Tree Example:
• Now insert 8
14
177
4 5311
128
13
AVL Tree Example:
• Now the AVL tree is balanced.
14
17
7
4
53
11
12
8 13
AVL Tree Example:
• Now remove 53
14
17
7
4
53
11
12
8 13
AVL Tree Example:
• Now remove 53, unbalanced
14
17
7
4
11
12
8 13
AVL Tree Example:
• Balanced! Remove 11
14
17
7
4
11
128
13
AVL Tree Example:
• Remove 11, replace it with the largest in its left branch
14
17
7
4
8
12
13
AVL Tree Example:
• Remove 8, unbalanced
14
17
4
7
12
13
AVL Tree Example:
• Remove 8, unbalanced
14
17
4
7
12
13
AVL Tree Example:
• Balanced!!
14
174
7
12
13
• Build an AVL tree with the following values:15, 20, 24, 10, 13, 7, 30, 36, 25