Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Distinct keys [6, 20, 4, 25, 16] are inserted, in the order given by the sequence [16, 25, 20, 6, 4], 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. 6
- C. 24
- D. 42
Correct answer: B. 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
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–F (1), A–G (1), B–C (1), B–G (1), C–D (1), C–G (1), E–G (1)…
- Array A = [6, 7, 4, 1, 8, 8, 7] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→B (4), A→C…
- Array A = [2, 2, 4, 4, 1, 5, 2, 3, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: B–D (7), A–D (7), C–D (9), D–E (3), A–C (2)…
- Directed weighted graph on vertices A, D, B, F, C (source A, target C) with edges: A→D (4); A→B (7); B→D (-6); D→C (3); B→C (1); A→C (12)…