Data Structures & AlgorithmsVery hardProduct-company placement

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

  1. A. 152
  2. B. 221
  3. C. 277
  4. D. 16

Correct answer: A. 152

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 4 is F(7, 4) − F(7, 3) = 221 − 69 = 152.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic