Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 D
A binary search tree has 5 distinct keys and preorder traversal 34 9 6 50 38. 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. 120
- B. 42
- C. 24
- D. 6
Correct answer: D. 6
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 39 28 3 36 31. How many of the 5! orders in which these keys can be…
- A binary search tree has 6 distinct keys and preorder traversal 21 9 13 41 32 39. How many of the 6! orders in which these keys can be…
- A binary search tree has 6 distinct keys and preorder traversal 40 3 25 19 47 43. How many of the 6! orders in which these keys can be…
- A binary search tree has 6 distinct keys and preorder traversal 9 42 22 23 35 50. How many of the 6! orders in which these keys can be…
- A binary search tree has 6 distinct keys and preorder traversal 40 37 22 13 24 48. How many of the 6! orders in which these keys can be…
- A binary search tree has 7 distinct keys and preorder traversal 12 3 58 27 15 24 50. How many of the 7! orders in which these keys can be…