Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Distinct keys are inserted in this order into an empty binary search tree: 42 36 66 99 50 43 95 86 74 47 18 83. The node with key 42, which has two children, is deleted. It is replaced by its inorder successor (the smallest key in its right subtree), and that successor's node is removed from its old place. What is the preorder traversal of the tree afterwards?

  1. A. 36 18 66 50 43 47 99 95 86 74 83
  2. B. 43 36 18 66 50 43 47 99 95 86 74 83
  3. C. 43 36 18 66 50 47 99 95 86 74 83
  4. D. 36 18

Correct answer: C. 43 36 18 66 50 47 99 95 86 74 83

After the swap the successor key sits where 42 was and its old node is gone. Using the predecessor instead, leaving the successor node in place, or keeping only the left subtree gives the trap answers.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic