Data Structures & AlgorithmsHardProduct-company MCQ pattern

Keys 50, 30, 70, 20, 40, 60, 80, 65 are inserted into an empty BST, then 50 is deleted by replacing it with its inorder SUCCESSOR. What is the preorder traversal afterwards?

  1. A. 65 30 20 40 70 60 80
  2. B. 60 30 20 40 70 65 80
  3. C. 40 30 20 70 60 65 80
  4. D. 60 30 20 40 70 80 65

Correct answer: B. 60 30 20 40 70 65 80

The successor of 50 is the leftmost key of its right subtree, 60. 60 moves to the root and its right child 65 takes its place under 70. Preorder: 60 30 20 40 70 65 80. Using the predecessor (40) would give the second option.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic