Data Structures & AlgorithmsModerateGATE CS · Infosys Mysore
Distinct keys are inserted one by one, in the order 86 89 26 11 73, 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. 86 89 26 73 11
- B. 86 26 11 73 89
- C. 11 73 26 89 86
- D. 86 26 89 11 73
Correct answer: B. 86 26 11 73 89
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 40 38 28 68 61, into an empty binary search tree (a smaller key goes to the left, a…
- 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…
- 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…