Data Structures & AlgorithmsVery hardProduct-company MCQ pattern

How many of the 7! insertion orders of the keys 1–7 produce the perfectly balanced BST with root 4, children 2 and 6, and leaves 1, 3, 5, 7?

  1. A. 16
  2. B. 1
  3. C. 80
  4. D. 48

Correct answer: C. 80

4 must come first. The 6 remaining keys split into {1, 2, 3} and {5, 6, 7}; their relative interleaving can be anything: C(6, 3) = 20. Within each side, the subtree root (2 or 6) must come first and its two children in either order: 2 × 2. Total 20 × 4 = 80.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic