Data Structures & AlgorithmsHardGATE CS · Infosys Mysore
Distinct keys are inserted one by one, in the order 98 75 51 16 34 70 48 57, into an empty binary search tree (a smaller key goes to the left, a larger key to the right). What is the preorder traversal of the resulting tree?
- A. 98 75 51 70 57 16 34 48
- B. 48 34 16 57 70 51 75 98
- C. 98 75 51 16 34 48 70 57
- D. 98 75 51 16 70 34 57 48
Correct answer: C. 98 75 51 16 34 48 70 57
Each insertion walks down from the root by comparing with the current node, so the first key is the root. Preorder then prints root, left subtree, right subtree; the mirror-image rule of putting larger keys left is a common slip.
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 one by one, in the order 68 40 11 59 83 33 97 85 57, into an empty binary search tree (a smaller key goes to…
- Distinct keys are inserted one by one, in the order 71 54 52 33 67 25 91, into an empty binary search tree (a smaller key goes to the…
- Distinct keys are inserted one by one, in the order 74 87 64 14 59 10 32, into an empty binary search tree (a smaller key goes to the…
- Distinct keys are inserted one by one, in the order 97 11 93 94 45 38 51 83, into an empty binary search tree (a smaller key goes to the…
- Distinct keys are inserted one by one, in the order 37 47 24 29 58 80 35, into an empty binary search tree (a smaller key goes to the…
- Distinct keys are inserted one by one, in the order 81 86 27 73 34 76 35 64 57, into an empty binary search tree (a smaller key goes to…