Data Structures & AlgorithmsVery hardGATE CS

How many structurally distinct binary trees with 8 nodes have at most 4 levels (a single root alone is 1 level)?

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

Correct answer: B. 94

Let B(n,h) count trees with n nodes and at most h levels: B(n,h)=sum of B(i,h-1)*B(n-1-i,h-1). Then B(8,4)=94; with no depth limit the count is the Catalan number C8=1430.

More Coding Interview Problems questions

Exams that ask this topic