GATE Computer ScienceVery hardGATE CSE · NIELIT

Keys 1–7 are inserted into an empty BST in the order 4, 2, 6, 1, 3, 5, 7, giving a perfectly balanced tree. How many of the 5040 insertion orders of 1–7 produce exactly this same tree?

  1. A. 64
  2. B. 80
  3. C. 40
  4. D. 120

Correct answer: B. 80

The root must be first and the two subtrees' insertions interleave arbitrarily: C(6,3) × 2 × 2 = 80.

More Algorithms questions

Exams that ask this topic