GATE Computer ScienceHardGATE CSE

Keys 40, 20, 60, 10, 30, 50, 70, 25, 35, 45, 65 are inserted into an empty BST. The root 40 is then deleted, replacing it by its inorder successor. What is the preorder traversal of the resulting tree?

  1. A. 45 20 10 30 25 35 60 50 70 65
  2. B. 50 20 10 30 25 35 60 45 70 65
  3. C. 45 20 10 30 25 35 60 50 65 70
  4. D. 45 20 10 30 25 35 60 50 70 65 55

Correct answer: A. 45 20 10 30 25 35 60 50 70 65

The inorder successor of 40 is 45 (leftmost in the right subtree). Replacing 40 by 45 and removing the leaf gives preorder 45 20 10 30 25 35 60 50 70 65.

More Programming and Data Structures (GATE) questions

Exams that ask this topic