Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Notes

for
AVL Trees

Made By:-
Prashansa Taneja
(Assistant Professor,
CSE Department,
AP Goyal Shimla University)
AVL Trees:-
Consider the elements A, B, C, D to be inserted into a binary search tree as shown in Fig.
below. Observe how the binary search tree turns out to be right skewed. Again the insertion
of elements A, B, C, D in that order in the binary search tree results in a left skewed binary
search tree. The disadvantage of a skewed binary search tree is that the worst case time
complexity of a search is O(n). Therefore there arises the need to maintain the binary search
tree to be of balanced height. By doing so it is possible to obtain for the search operation a
time complexity of O(log n) in the worst case. One of the more popular balanced trees was
introduced in 1962 by Adelson—Velskii and Landis and was known as AVL trees.

Representation of AVL Trees:-

AVL search trees like binary search trees are represented using a linked representation.
However, every node registers its balance factor. AVL Tree can be defined as height
balanced binary search tree in which each node is associated with a balance factor which is
calculated by subtracting the height of its right sub-tree from that of its left sub-tree.

Tree is said to be balanced if balance factor of each node is in between -1 to 1, otherwise,


the tree will be unbalanced and need to be balanced.

Balance Factor (k) = height (left(k)) - height (right(k))

An AVL tree is given in the following figure. We can see that, balance factor associated with
each node is in between -1 and +1. Therefore, it is an example of AVL tree.
Complexity:-

S.No Algorithm Average case Worst case


1. Space o(n) o(n)

2. Search o(log n) o(log n)

3. Insert o(log n) o(log n)

4. Delete o(log n) o(log n)

You might also like