AVL Trees
Mohammad Mohsin
1. Definition
2. Problems of Binary Search Tree
3. Properties of AVL Tree
4. Insertion
5. Deletion
Contents
ALV Tree
AVL tree is a self-balancing Binary Search Tree(BST) where
the difference between height of left and right subtrees can not
be more than one for all nodes.
The AVL tree is named after its inventors, Georgy
Adelson-Velsky and Evgenii Landis.
Time Complexity: O(log2n).
Problems Of Binary Search Tree
Complexity: O(logn) Complexity: O(n)
Properties Of AVL Tree
A Binary tree is defined to be an AVL tree if the invariant
Balance Factor(N) ε { -1, 0, +1 }
holds for every node N in the tree where,
Balance factor(N) = Height of the left subtree(N) - Height of right subtree(N)
Steps for
Insertion
Let the newly inserted node be w
1. Perform standard Binary
Search Tree(BST) insert for w.
2. Starting from w, travel up and
find the first unbalanced node.
3. Rebalance the tree by
performing appropriate
rotations on the subtree.
Cases for Balancing the Tree
Let, z be the first unbalanced node, y be the child of z that comes on the
path from w to z and x is the grandchild of z that comes on the path from
w to z.
Then the following 4 possible arrangements are possible :
a. Left left case: y is the left child of z and x is the left child of y
b. Right right case: y is the right child of z and x is the right child of y.
c. Left right case: y is the left child of z and x is the right child of y.
d. Right left case: y is the right child of z and x is the left child of y
Left-Left Case:
(insert 6)
Right-Right Case:
(insert 48)
Left-Right Case:
(insert 21)
Right-Left Case:
(insert 36)
Problems Solution
LL R
RR L
LR LR
RL RL
Case Summarization
Deletion in AVL Trees
For deletion in AVL Tree,
1. Perform standard Binary Search Tree(BST) deletion
of the node.
2. Rebalance the tree by left or right rotation
Example of Deletion:
(delete 4)
Thank You

AVL Tress

  • 1.
  • 2.
    1. Definition 2. Problemsof Binary Search Tree 3. Properties of AVL Tree 4. Insertion 5. Deletion Contents
  • 3.
    ALV Tree AVL treeis a self-balancing Binary Search Tree(BST) where the difference between height of left and right subtrees can not be more than one for all nodes. The AVL tree is named after its inventors, Georgy Adelson-Velsky and Evgenii Landis. Time Complexity: O(log2n).
  • 4.
    Problems Of BinarySearch Tree Complexity: O(logn) Complexity: O(n)
  • 5.
    Properties Of AVLTree A Binary tree is defined to be an AVL tree if the invariant Balance Factor(N) ε { -1, 0, +1 } holds for every node N in the tree where, Balance factor(N) = Height of the left subtree(N) - Height of right subtree(N)
  • 6.
    Steps for Insertion Let thenewly inserted node be w 1. Perform standard Binary Search Tree(BST) insert for w. 2. Starting from w, travel up and find the first unbalanced node. 3. Rebalance the tree by performing appropriate rotations on the subtree.
  • 7.
    Cases for Balancingthe Tree Let, z be the first unbalanced node, y be the child of z that comes on the path from w to z and x is the grandchild of z that comes on the path from w to z. Then the following 4 possible arrangements are possible : a. Left left case: y is the left child of z and x is the left child of y b. Right right case: y is the right child of z and x is the right child of y. c. Left right case: y is the left child of z and x is the right child of y. d. Right left case: y is the right child of z and x is the left child of y
  • 8.
  • 9.
  • 10.
  • 11.
    Problems Solution LL R RRL LR LR RL RL Case Summarization
  • 12.
    Deletion in AVLTrees For deletion in AVL Tree, 1. Perform standard Binary Search Tree(BST) deletion of the node. 2. Rebalance the tree by left or right rotation
  • 13.
  • 14.