Data Structures & AlgorithmsVery hardGATE CS · Infosys Mysore
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 goes to the left, a larger key to the right). What is the preorder traversal of the resulting tree?
- A. 39 78 97 80 91 77 44 53 61 64 13 28
- B. 28 13 64 61 53 44 77 91 80 97 78 39
- C. 39 13 78 28 77 97 44 80 53 91 61 64
- D. 39 13 28 78 77 44 53 61 64 97 80 91
Correct answer: D. 39 13 28 78 77 44 53 61 64 97 80 91
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 in this order into an empty binary search tree: 46 26 52 59 92 79 84 21. A search is run for the key 72 (which…
- Distinct keys are inserted in this order into an empty binary search tree: 51 70 76 64 54 92 25 30. A search is run for the key 85 (which…
- Distinct keys are inserted in this order into an empty binary search tree: 26 41 30 45 83 99 61. A search is run for the key 40 (which is…
- Distinct keys are inserted in this order into an empty binary search tree: 71 94 46 89 99 65 66 80 58. A search is run for the key 94…
- Distinct keys are inserted in this order into an empty binary search tree: 58 14 45 67 75 50 62 85. A search is run for the key 78 (which…
- Distinct keys are inserted in this order into an empty binary search tree: 71 98 60 25 61 85 51 59. A search is run for the key 76 (which…