Data Structures & AlgorithmsHardProduct-company placement · GATE CS
The keys [47, 99, 2, 94, 90, 88, 97, 6, 8, 60, 30] 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. 7
- B. 5
- C. 11
- D. 6
Correct answer: D. 6
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 [23, 4, 71, 60, 98, 7, 85] are inserted, in this order, into an initially empty binary search tree (no rebalancing). How many…
- The keys [99, 12, 32, 75, 48, 66, 19, 63, 85, 55] are inserted, in this order, into an initially empty binary search tree (no…
- The keys [75, 40, 79, 13, 60, 24, 10, 88] are inserted, in this order, into an initially empty binary search tree (no rebalancing). How…
- 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…
- 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)…