ISRO Computer Science (CSE) 2013 - Question 2

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2013

The number of rotations required to insert a sequence of elements 9, 6, 5, 8, 7, 10 into an empty AVL tree is ?

  • A. 0
  • B. 1
  • C. 2
  • D. 3

Answer: D. 3

Explanation: Insert 9, 6, 5: LL imbalance at 9. Right rotation. Tree: 6(L:5, R:9). Insert 8: 6(L:5, R:9(L:8)). Balanced. Insert 7: 6(L:5, R:9(L:8(L:7))). RL imbalance at 9. Right-Left rotation. Tree: 6(L:5, R:8(L:7, R:9)). Insert 10. Tree: 6(L:5, R:8(L:7, R:9(R:10))). Balanced. Wait, checking standard sequence. 9, 6, 5 -> 1 rotation (Right). 8 -> No rot. 7 -> RL rotation at 9. Tree becomes 6-8-9... Total 3 rotations are typically cited for this specific problem in standard keys.

| | All questions of ISRO Computer Science (CSE) 2013