Data Structures & AlgorithmsVery hardTCS Digital · Product companies

Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 are inserted in order into an empty BST. Then 30 is deleted, then 50 is deleted; a node with two children is replaced by its inorder successor. What is the pre-order traversal of the final tree?

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

Correct answer: C. 60 35 20 40 45 70 65 80

Deleting 30 puts its successor 35 in its place (35 was 40's left child and disappears from there). Deleting 50 puts its successor 60 at the root, and 60's right child 65 moves up to take its place under 70, giving 60 35 20 40 45 70 65 80.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic