Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Distinct keys [10, 21, 12, 26, 19] are inserted, in the order given by the sequence [12, 21, 19, 10, 26], 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. 8
- D. 42
Correct answer: C. 8
Every order giving the same tree must start with the root and follow the same nesting, and there are exactly 8 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
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [20, 17, 5, 11, 19, 20], where Mi has size p[i−1] × p[i]…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–E (3), A–F (5), B–D (1), B–E (2), C–F (20), D–E (17), D–F…
- Directed weighted graph on vertices A, B, C, D with edges (u→v, w): D→B (3); B→C (4); A→C (6); D→A (2); A→D (2); D→C (6); B→A (8); B→D…
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: E→D (1); F→D (5); F→C (1); B→E (5); F→A (4)…
- Coins of denominations [12, 9, 8, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18?…
- Array A = [9, 3, 3, 8, 2, 4, 3] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…