Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 D
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 inserted, one at a time, into an empty binary search tree produce exactly this tree?
- A. 10
- B. 720
- C. 132
- D. 120
Correct answer: A. 10
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 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…
- A binary search tree has 6 distinct keys and preorder traversal 52 1 3 23 48 53. How many of the 6! orders in which these keys can be…
- A binary search tree has 7 distinct keys and preorder traversal 50 21 4 31 28 57 55. How many of the 7! orders in which these keys can be…
- A tree on vertices 1 to 6 has the edges 4–5, 1–6, 6–4, 3–1, 2–5. Compute its Prüfer code: repeat 4 times, delete the smallest-labelled…
- A tree on vertices 1 to 6 has the edges 6–2, 4–6, 2–3, 3–5, 1–2. Compute its Prüfer code: repeat 4 times, delete the smallest-labelled…
- A tree on vertices 1 to 7 has the edges 3–6, 4–1, 7–6, 1–5, 2–4, 6–1. Compute its Prüfer code: repeat 5 times, delete the…