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)?

  1. A. 132
  2. B. 720
  3. C. 15
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic