Data Structures & AlgorithmsVery hardProduct-company placement · GATE CS
The keys [29, 31, 12, 73, 89, 19, 39, 87] are inserted, in this order, into an initially empty binary search tree (no rebalancing). How many nodes lie on the longest root-to-leaf path, counting both the root and the leaf?
- A. 4
- B. 8
- C. 6
- D. 5
Correct answer: D. 5
Insertion walks left for smaller keys and right otherwise. The longest path counted in nodes is one more than its length in edges; reporting the edge count, or the total number of nodes, is the usual 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
- The keys [51, 64, 57, 69, 40, 23, 99] are inserted, in this order, into an initially empty binary search tree (no rebalancing). How many…
- The keys [50, 86, 83, 88, 23, 30, 91, 31, 68] are inserted, in this order, into an initially empty binary search tree (no rebalancing)…
- 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…
- 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…