Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D
Distinct keys are inserted in this order into an empty binary search tree: 24 51 61 90 94 68 32 41 33 28 47. The node with key 41, 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?
- A. 24 51 32 28 47 33 61 90 68 94
- B. 24 51 32 28 33 47 61 90 68 94
- C. 24 51 32 28 47 33 47 61 90 68 94
- D. 24 51 32 28 33 61 90 68 94
Correct answer: A. 24 51 32 28 47 33 61 90 68 94
After the swap the successor key sits where 41 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Distinct keys are inserted in this order into an empty binary search tree: 63 14 59 74 16 60 70 33 88 26 85 68 19 91. The node with key…
- Distinct keys are inserted in this order into an empty binary search tree: 32 98 78 65 61 33 77 23 44 48 17. The node with key 65, which…
- Distinct keys are inserted in this order into an empty binary search tree: 76 56 13 71 58 86 42 12 35 32 55 18 29 28. The node with key…
- Distinct keys are inserted in this order into an empty binary search tree: 38 64 24 66 75 14 10 42 62 60 19 98 53. The node with key 64…
- Distinct keys are inserted in this order into an empty binary search tree: 70 87 76 92 37 93 83 81 19 77 88 59 48 17. The node with key…
- 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…