Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Distinct keys [25, 10, 8, 14, 19] are inserted, in the order given by the sequence [19, 8, 14, 10, 25], 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. 120
- B. 24
- C. 42
- D. 4
Correct answer: D. 4
Every order giving the same tree must start with the root and follow the same nesting, and there are exactly 4 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
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (3), A–C (3), A–D (1), B–E (1), C–D (2), C–E (3). How many distinct…
- Distinct keys [3, 21, 7, 19, 24] are inserted, in the order given by the sequence [7, 21, 19, 24, 3], into an empty binary search tree…
- Connected undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (1), A–D (4), B–C (1), B–D (2), C–D (6). Among all…
- Array A = [2, 24, 11, 16, 9, 22, 23, 10, 19]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- Strings a = "ccbab" and b = "bbbcaa". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→B, B→F, C→D, A→G, F→D, G→F, D→C, G→B, C→G (no weights). What is the number of…