Data Structures & AlgorithmsVery hardProduct-company placement

Keys 19, 93, 16, 51, 81, 18, 92, 41 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. 3
  3. C. 126
  4. D. 63

Correct answer: D. 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