0% found this document useful (0 votes)
27 views6 pages

AVL Tree

Uploaded by

navdeep242006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

AVL Tree

Uploaded by

navdeep242006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

AVL Tree

Data Structure
AVL Tree
 AVL Tree is invented by GM Adelson - Velsky and EM
Landis in 1962. The tree is named AVL in honour of
its inventors.
 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))
 If balance factor of any node is 1, it means that
the left sub-tree is one level higher than the right
sub-tree.
 If balance factor of any node is 0, it means that
the left sub-tree and right sub-tree contain equal
height.
 If balance factor of any node is -1, it means that
the left sub-tree is one level lower than the right
sub-tree.
 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.
Example of AVL Tree
Why AVL Tree?
 AVL tree controls the height of the binary
search tree by not letting it to be skewed.
The time taken for all operations in a binary
search tree of height h is O(h). However, it
can be extended to O(n) if the BST
becomes skewed (i.e. worst case). By
limiting this height to log n, AVL tree
imposes an upper bound on each operation
to be O(log n) where n is the number of
nodes.
AVL Rotations
 We perform rotation in AVL tree only in case if
Balance Factor is other than -1, 0, and 1. There
are basically four types of rotations which are as
follows:
 L L rotation: Inserted node is in the left subtree of
left subtree of A
 R R rotation : Inserted node is in the right subtree
of right subtree of A
 L R rotation : Inserted node is in the right subtree
of left subtree of A
 R L rotation : Inserted node is in the left subtree
of right subtree of A

You might also like