0% found this document useful (0 votes)
50 views

COMPABTech45442rDatrAP - AVL Trees PDF

This document provides information about AVL trees. AVL trees are self-balancing binary search trees where the heights of the two child subtrees of any node differ by at most one. This balancing ensures that insertions and deletions complete in O(log n) time. The document defines the balance factor of a node as the height of its left subtree minus the height of its right subtree. An AVL tree remains balanced if the balance factor of every node is between -1 and 1.

Uploaded by

amascov
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

COMPABTech45442rDatrAP - AVL Trees PDF

This document provides information about AVL trees. AVL trees are self-balancing binary search trees where the heights of the two child subtrees of any node differ by at most one. This balancing ensures that insertions and deletions complete in O(log n) time. The document defines the balance factor of a node as the height of its left subtree minus the height of its right subtree. An AVL tree remains balanced if the balance factor of every node is between -1 and 1.

Uploaded by

amascov
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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