The document discusses AVL trees, which are self-balancing binary search trees. It describes the balance factor calculation and the different rotation techniques used to rebalance the tree, including left, right, left-right and right-left rotations.
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 ratings0% found this document useful (0 votes)
195 views11 pages
Avl Tree
The document discusses AVL trees, which are self-balancing binary search trees. It describes the balance factor calculation and the different rotation techniques used to rebalance the tree, including left, right, left-right and right-left rotations.
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
You are on page 1/ 11
AVL - TREE
Presented by- Urvi Sharma
What is an AVL tree? AVL tree is a tree which can be skewed either left or right. Avl trees are balanced binary trees whose worst case time complexity is equivalent to Binary search It is named after the inventor Adelson, Velski & Landis. AVL trees are height balancing binary search tree. Balance factor:- Toc create the Avl tree we need to keep in mind the Balance factor Balance factor is calculated as- BalanceFactor = height(left-sutree) − height(right-sutree)
The nodes of tree having balance factor = 0,1,-1 is called Balance
tree.
When a node gets value other than these 3 , it is called Unbalanced
tree. TYPES OF AVL trees Left rotation
Right rotation
Left-right rotation
Right-Left rotation Left Rotation:- If a tree becomes unbalanced, when a node is inserted into the right subtree of the right subtree, then we perform a single left rotation −
In our example, node A has become unbalanced as a node is
inserted in the right subtree of A's right subtree. We perform the left rotation by making A the left-subtree of B. Right Rotation:- AVL tree may become unbalanced, if a node is inserted in the left subtree of the left subtree. The tree then needs a right rotation.
As depicted, the unbalanced node becomes the
right child of its left child by performing a right rotation. Left-Right Rotation A left-right rotation is a combination of left rotation followed by right rotation.
A node has been inserted into the right subtree
of the left subtree. This makes C an unbalanced node. These scenarios cause AVL tree to perform left-right rotation
Node C is still unbalanced, however now, it is because of the left- sub
tree of the left sub tree. Node c is still unbalanced,however now its because of the left subtree of the left subtree.
We shall now right-rotate the tree, making
B the new root node of this subtree, C now becomes the right subtree of its own left subtree.
The tree is now balanced.
Right-Left Rotation:- The second type of double rotation is Right-Left Rotation. It is a combination of right rotation followed by left rotation.
A node has been inserted into the
left subtree of the right subtree. This makes A, an unbalanced node with balance factor 2.
First, we perform the right rotation along C node,
making C the right subtree of its own left subtree B. B. Now, B becomes the right subtree of A. Node A is still unbalanced because of the right subtree of its right subtree and requires a left rotation.
A left rotation is performed by making B the new
root node of the subtree. A becomes the left subtree of its right subtree B.