Data Structures & AlgorithmsVery hardGATE CS · Infosys Mysore
Distinct keys are inserted one by one, in the order 59 81 64 76 91 72 87 11 48 37, 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. 59 81 91 87 64 76 72 11 48 37
- B. 59 11 48 37 81 64 76 72 91 87
- C. 37 48 11 72 76 64 87 91 81 59
- D. 59 11 81 48 64 91 37 76 87 72
Correct answer: B. 59 11 48 37 81 64 76 72 91 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 97 59 15 80 75 66 23 56 21 36 77, into an empty binary search tree (a smaller key goes…
- Distinct keys are inserted one by one, in the order 11 14 77 49 19 68 86 32 78 52 28, into an empty binary search tree (a smaller key goes…
- Distinct keys are inserted one by one, in the order 40 47 38 13 69 73 21 41 71 48 46 89, into an empty binary search tree (a smaller key…
- Distinct keys are inserted one by one, in the order 97 33 52 32 57 89 24 34 87 37, into an empty binary search tree (a smaller key goes to…
- Distinct keys are inserted one by one, in the order 49 84 21 29 17 35 89 31 43 24, into an empty binary search tree (a smaller key goes to…
- Distinct keys are inserted one by one, in the order 39 78 13 28 97 77 80 44 53 61 91 64, into an empty binary search tree (a smaller key…