Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

Keys 90, 94, 89, 30, 62, 17, 99, 53 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into an empty BST, produce exactly the same tree?

  1. A. 21
  2. B. 63
  3. C. 3
  4. D. 126

Correct answer: B. 63

A node must come before every key in its subtree, but its two subtrees may interleave freely: count = C(n−1, |left|) × count(left) × count(right) = 63, which also equals n!/∏(subtree sizes).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic