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.
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
Recommended Posts:
- Data Structures | Balanced Binary Search Trees | Question 2
- Data Structures | Balanced Binary Search Trees | Question 2
- Data Structures | Balanced Binary Search Trees | Question 10
- Data Structures | Balanced Binary Search Trees | Question 4
- Data Structures | Balanced Binary Search Trees | Question 13
- Data Structures | Balanced Binary Search Trees | Question 7
- Data Structures | Balanced Binary Search Trees | Question 13
- Data Structures | Balanced Binary Search Trees | Question 9
- Data Structures | Balanced Binary Search Trees | Question 13
- Data Structures | Balanced Binary Search Trees | Question 11
- Data Structures | Balanced Binary Search Trees | Question 12
- Data Structures | Balanced Binary Search Trees | Question 13
- Data Structures | Binary Search Trees | Question 1
- Data Structures | Binary Search Trees | Question 2
- Data Structures | Binary Search Trees | Question 3
- Data Structures | Binary Search Trees | Question 4
- Data Structures | Binary Search Trees | Question 5
- Data Structures | Binary Search Trees | Question 6
- Data Structures | Binary Search Trees | Question 7
- Data Structures | Binary Search Trees | Question 8

