AVL Tree
AVL Tree
AVL Tree
AVL tree is a binary search tree in which the difference of heights of left and
right subtrees of any node is less than or equal to one.
• After adjustment the binary search tree, balanced factor must be equal to
one of them (- 1 , 0 , 1 ).
• Concept of AVL only works on binary search tree.
AVL Rotations
We perform rotation in AVL tree only in case if Balance Factor is other than
( -1 , 0 , 1 ).
1. RR Rotation
When binary search tree(BST) becomes unbalanced, due to a node is inserted
into the right subtree of the right subtree of A, then we perform RR rotation.
• RR rotation is an anticlockwise rotation, which is applied on the edge
below a node having balance factor -2.
2. LL Rotation
When binary search tree(BST) becomes unbalanced, due to a node is inserted
into the left subtree of the left subtree of C,then we perform LL rotation.
3. LR Rotation
• LR rotation = RR rotation + LL rotation.
• First RR rotation is performed on subtree.
• Then LL rotation is performed on full tree.
By full tree we mean the first node from the path of inserted node whose
balance factor is other than -1, 0, or 1.
4. RL Rotation
• R L rotation= LL rotation + RR rotation.
• First LL rotation is performed on subtree.
• Then RR rotation is performed on full tree.
By full tree we mean the first node from the path of inserted node whose
balance factor is other than -1, 0, or 1.