Data Structures & AlgorithmsHardProduct-company placement · GATE CS
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). How many nodes lie on the longest root-to-leaf path, counting both the root and the leaf?
- A. 5
- B. 4
- C. 3
- D. 9
Correct answer: B. 4
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 [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…
- 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…