GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Keys 40, 20, 10, 25, 30, 22, 50, 5, 3, 35, 45, 60 are inserted in this order into an initially empty AVL tree (a double rotation counts as 2 rotations). What is the total number of rotations performed and the preorder traversal of the final tree?

  1. A. 6 rotations; 25 20 5 3 10 22 40 30 35 50 45 60
  2. B. 7 rotations; 25 20 5 3 10 22 40 30 35 50 45 60
  3. C. 7 rotations; 25 20 5 3 10 22 40 30 35 50 45
  4. D. 8 rotations; 3 5 10 20 22 25 30 35 40 45 50 60

Correct answer: B. 7 rotations; 25 20 5 3 10 22 40 30 35 50 45 60

Simulating each insertion with the usual LL, RR, LR and RL cases gives 7 rotations in all and the final preorder shown.

More Programming and Data Structures (GATE) questions

Exams that ask this topic