Avl Tree
Avl Tree
Avl Tree
com/gate/avl-trees-notes/
Fibonaci Heap:
Drawback of AVL
VL Tree is an essential topic under one of the most important chapters of Computer Science i.e.
Data Structure. And, when it comes to a competitive examination like GATE, you have to dive deep
into this topic to understand it thoroughly. In this article, we have comprised all the pointers related to
the AVL Tree. We hope these notes for CSE topics will help you understand this topic in a better
way.
The term AVL tree was introduced by Adelson-Velsky and Landis. It is a balanced binary search tree
and is the first data structure like this. In the AVL tree, the heights of the subtree cannot be more
than one for all nodes.
The above picture is of an AVL tree. Here, it is clearly visible that the heights of the left and right
subtrees are equal to, or less than one.
The above tree is not an AVL tree. And, the reason is simple. Here, the heights of the left and right
subtrees are higher than 1.
In the above example, the height of the left subtree is 3 and the height of the right subtree is 2. That
means the balance factor is <=1 therefore the tree is supposed to be balanced.
1. Insertion
2. Deletion
Insertion: The process of insertion is the same as it is executed in the binary search tree. However,
there are chances that it may point to a violation in the AVL tree property, and the tree may require
balancing. To balance a tree we can apply rotations.
Deletion: The process of deletion is the same as it is executed in a binary search tree. It can affect
the balance factor of the tree, therefore, we need to utilize different types of rotations to balance the
tree.
AVL Rotation
Left rotation
Right rotation
Left-Right rotation
Right-Left rotation
1.
1. Left Rotation: When we perform insertion at the left subtree, then it is a left rotation.
1.
1. Right Rotation: When we perform insertion at the right subtree, then it is a right
rotation.
1.
1. Left-Right Rotation
1. Right-Left Rotation
Figure: Right-Left Rotation
Max-Heap − Where the value of the root node is greater than or equal to either of its children.
Both trees are constructed using the same input and order of arrival.