Data Structures & AlgorithmsModerateGATE CS · Infosys Mysore
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 larger key to the right). What is the preorder traversal of the resulting tree?
- A. 40 68 61 38 28
- B. 28 38 61 68 40
- C. 40 38 28 68 61
- D. 40 38 68 28 61
Correct answer: C. 40 38 28 68 61
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 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…
- 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…