Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Distinct keys [13, 24, 18, 4, 20] are inserted, in the order given by the sequence [18, 20, 4, 24, 13], 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. 6
- B. 42
- C. 24
- D. 120
Correct answer: A. 6
Every order giving the same tree must start with the root and follow the same nesting, and there are exactly 6 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
- Distinct words ['baa', 'c', 'b', 'bac', 'bba', 'cbbc'] are inserted into an empty trie (one node per character, shared prefixes sharing…
- Directed graph on vertices A, B, C, D, E, F with edges E→D, A→D, F→C, E→C, A→E, B→C, A→F, D→A. How many strongly connected components does…
- Strings a = "bbbab" and b = "cccbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Coins of denominations [6, 5, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 16? (Coins…
- Words ['b', 'a', 'aaba', 'cab', 'baca', 'b'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Array A = [30, 20, 28, 25, 2, 19, 15, 7, 11]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…