Data Structures & AlgorithmsVery hardProduct-company placement

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

  1. A. 69
  2. B. 68
  3. C. 361
  4. D. 8

Correct answer: B. 68

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 3 is F(7, 3) − F(7, 2) = 69 − 1 = 68.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic