GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many structurally distinct binary search trees on keys 1..7 have key 4 at the root and height exactly 3 (a single node has height 0)?

  1. A. 24
  2. B. 25
  3. C. 1
  4. D. 31

Correct answer: A. 24

Root 4 leaves 3 keys on each side, 5 shapes per side (C3 = 5), 25 trees in all. The height is 3 when at least one side is a chain of 3 (height 2): sides of height at most 1 give 1 shape (perfect) so 24 trees have height exactly 3.

More Programming and Data Structures (GATE) questions

Exams that ask this topic