Data Structures & AlgorithmsVery hardGATE CS

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

  1. A. 26
  2. B. 20
  3. C. 22
  4. D. 8

Correct answer: B. 20

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(5, 3) − F(5, 2) = 26 − 6 = 20.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic