Skip to content
Related Articles
Open in App
Not now

Related Articles

Data Structures | Balanced Binary Search Trees | Question 5

Improve Article
Save Article
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

Consider the following AVL tree.

         60
      /     \  
    20      100
           /   \
         80    120     

Which of the following is updated AVL tree after insertion of 70

A
        70
      /    \  
    60      100
   /       /    \
 20       80    120 

B
        100
      /    \  
    60      120
   /  \     /  
 20   70   80   


C
        80
      /    \  
    60      100
   /  \       \
 20   70      120

D
        80
      /    \  
    60      100
   /       /   \
 20      70    120  

(A) A
(B) B
(C) C
(D) D


Answer: (C)

Explanation: Refer following for steps used in AVL insertion.

AVL Tree | Set 1 (Insertion)

After insertion of 70, tree becomes following
         60
      /     \  
    20      100
           /   \
         80    120     
        /
       70

We start from 50 and travel up. We keep travelling up till we find an unbalanced node. In above case, we reach the node 60 and see 60 got unbalanced after insertion and this is Right Left Case. So we need to apply two rotations

         60                               60                            80
      /     \       Right Rotate(100)  /      \     Left Rotate(60)   /    \
    20      100    -----------------> 20        80 ---------------> 60      100 
           /   \                              /   \                /  \        \
         80    120                          70     100            20   70       120  
        /                                            \    
      70                                             120 


Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!