Data Structures & AlgorithmsHardGATE CS · Infosys Mysore
Distinct keys are inserted one by one, in the order 31 45 91 79 26 76 52 36 87, 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. 31 45 91 79 87 76 52 36 26
- B. 26 36 52 76 87 79 91 45 31
- C. 31 26 45 36 91 79 76 87 52
- D. 31 26 45 36 91 79 76 52 87
Correct answer: D. 31 26 45 36 91 79 76 52 87
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 84 43 68 61 70 58 73 94, into an empty binary search tree (a smaller key goes to the…
- Distinct keys are inserted one by one, in the order 62 76 83 50 90 49 38, into an empty binary search tree (a smaller key goes to the…
- 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…
- 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…