Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

Keys are inserted in the order 56 88 11 17 79 25 68 into an empty binary search tree. Then the key 56 (which has two children) is deleted by replacing it with its INORDER SUCCESSOR, and the successor node is removed from the right subtree. What is the preorder traversal (root, left, right) of the tree afterwards? Give the keys separated by spaces.

  1. A. 56 11 17 25 88 79 68
  2. B. 68 11 17 25 88 79
  3. C. 25 11 17 88 79 68
  4. D. 68 11 17 25 88 79 68

Correct answer: B. 68 11 17 25 88 79

The successor (smallest key of the right subtree) replaces 56, so the preorder becomes 68 11 17 25 88 79. Using the predecessor instead gives a different shape, and forgetting to remove the successor node leaves a duplicate.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic