GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many structurally different binary search trees can be built on the keys 1..7 such that the height is at most 3 (a single node has height 0)?

  1. A. 429
  2. B. 69
  3. C. 365
  4. D. 1

Correct answer: B. 69

Of the C7 = 429 shapes, those of height at most 3 satisfy f(n, h) = sum over l of f(l, h-1) f(n-1-l, h-1) with f(0, h) = 1; evaluating it for n = 7, h = 3 gives 69.

More Programming and Data Structures (GATE) questions

Exams that ask this topic