Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
The keys [88, 87, 65, 73, 34, 44] are inserted, in this order, into an initially empty binary search tree. What is the preorder traversal (visit root, then left subtree, then right subtree) of the resulting tree?
- A. 34 44 65 73 87 88
- B. 44 34 73 65 87 88
- C. 88 87 65 34 44 73
- D. 88 87 65 34 73 44
Correct answer: C. 88 87 65 34 44 73
Preorder lists the root first and then recurses on the left and right subtrees. The BST shape is set by the insertion order, so sorting the keys or reading them level by level gives a different sequence.
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
- The keys [29, 53, 76, 4, 31, 57, 23, 22, 69, 99] are inserted, in this order, into an initially empty binary search tree. What is the…
- The keys [28, 5, 61, 79, 58, 30, 29, 36, 13] are inserted, in this order, into an initially empty binary search tree. What is the preorder…
- The keys [37, 78, 4, 15, 76, 26, 11] are inserted, in this order, into an initially empty binary search tree. What is the preorder…
- The keys [93, 91, 80, 52, 48, 31, 54] are inserted, in this order, into an initially empty binary search tree. What is the preorder…
- The keys [25, 47, 8, 58, 9, 73] are inserted, in this order, into an initially empty binary search tree. What is the preorder traversal…
- The keys [94, 74, 35, 49, 5, 67, 58, 4, 18] are inserted, in this order, into an initially empty binary search tree. What is the preorder…