GATE Computer ScienceHardGATE CS (PYQ pattern)

Insert 45, 25, 65, 15, 35, 55, 75, 10, 20, 30, 40, 50, 60 into an empty BST. Then delete 25, 45 and 65 in that order, replacing a node having two children by its inorder successor. What is the preorder traversal of the resulting tree?

  1. A. 50 30 15 10 20 35 40 75 55 60
  2. B. 15 10 35 20 30 55 40 50 75 60
  3. C. 40 20 15 10 35 30 60 55 50 75
  4. D. 60 55 75 40 35 20 10 15 30 50

Correct answer: A. 50 30 15 10 20 35 40 75 55 60

Deleting 25 pulls up 30, deleting 45 pulls up 50, deleting 65 pulls up 75. Using the predecessor, or rebuilding from the remaining keys, gives different shapes.

More Programming and Data Structures (GATE) questions

Exams that ask this topic