Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Distinct keys [13, 25, 27, 11, 8, 16] are inserted, in the order given by the sequence [25, 13, 8, 27, 16, 11], into an empty binary search tree. How many of the permutations of these same keys, when inserted in that order into an empty BST, produce exactly the same tree (same keys in the same positions)?
- A. 132
- B. 720
- C. 15
- D. 120
Correct answer: C. 15
Every order giving the same tree must start with the root and follow the same nesting, and there are exactly 15 of them. The total n! or the count matching only the shape are different quantities.
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
- Words ['c', 'cbca', 'bbaa', 'a', 'c', 'cca', 'cca'] are inserted in this order into an empty trie with one node per character, shared…
- Undirected graph on vertices A, B, C, D, E, F with weighted edges A–B (5), A–C (6), A–D (4), A–F (3), B–D (8), B–E (5), B–F (6), C–F (6)…
- Array A = [27, 21, 20, 5, 13, 9, 28] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Coins of denominations [11, 10, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 20?…
- Weighted tree on vertices 0 to 7 with edges 0–1 (9), 0–2 (2), 1–3 (4), 0–4 (3), 2–5 (3), 5–6 (2), 6–7 (7). What is the largest possible…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: A–D (2), A–C (3), A–F (6), B–C (5), D–E (5)…