Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

How many structurally different binary trees with 7 nodes have height EXACTLY 5 (height = edges on the longest root-to-leaf path)?

  1. A. 365
  2. B. 144
  3. C. 285
  4. D. 32

Correct answer: B. 144

Let F(n, h) count trees with n nodes and height ≤ h: F(n, h) = Σ F(i, h−1)·F(n−1−i, h−1). Exactly 5 is F(7, 5) − F(7, 4) = 365 − 221 = 144.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic