Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band

Distinct keys [5, 4, 7, 27, 25] are inserted, in the order given by the sequence [25, 5, 4, 27, 7], 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. 42
  2. B. 120
  3. C. 8
  4. D. 24

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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic