Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 D
A binary search tree has 5 distinct keys and preorder traversal 34 18 6 29 57. How many of the 5! orders in which these keys can be inserted, one at a time, into an empty binary search tree produce exactly this tree?
- A. 8
- B. 120
- C. 42
- D. 24
Correct answer: A. 8
Insertion order must put each parent before its descendants, so the count is the number of linear extensions of the tree: n! divided by the product of all subtree sizes. The total n!, the Catalan number, and the product itself are the traps.
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
- A binary search tree has 5 distinct keys and preorder traversal 37 5 33 53 39. How many of the 5! orders in which these keys can be…
- A binary search tree has 4 distinct keys and preorder traversal 19 26 58 50. How many of the 4! orders in which these keys can be…
- A binary search tree has 5 distinct keys and preorder traversal 17 6 32 38 55. How many of the 5! orders in which these keys can be…
- A binary search tree has 5 distinct keys and preorder traversal 35 11 5 36 44. How many of the 5! orders in which these keys can be…
- A binary search tree has 6 distinct keys and preorder traversal 14 5 11 30 41 42. How many of the 6! orders in which these keys can be…
- A binary search tree has 6 distinct keys and preorder traversal 31 18 8 26 48 59. How many of the 6! orders in which these keys can be…