GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A full binary tree has every node with 0 or 2 children; left and right are distinguished. How many structurally different full binary trees have exactly 9 leaves and height at most 4 (a single node has height 0)?

  1. A. 1430
  2. B. 470
  3. C. 94
  4. D. 158

Correct answer: C. 94

Let F(L, h) count full trees with L leaves and height <= h: F(1, h) = 1, F(L, 0) = 0 for L > 1, and F(L, h) = sum over a = 1..L-1 of F(a, h-1) F(L-a, h-1). Height <= 3 allows at most 8 leaves, so F(9, 3) = 0; computing F(9, 4) gives 94, far fewer than the unrestricted Catalan count C8 = 1430.

More Programming and Data Structures (GATE) questions

Exams that ask this topic