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