Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Problem: How many binary trees (distinct shapes, ignoring labels) can be formed with 6 nodes?

  1. A. 42
  2. B. 429
  3. C. 720
  4. D. 132

Correct answer: D. 132

Binary-tree shapes with n nodes are counted by the Catalan number C(n) = Σ C(i)·C(n − 1 − i), so C(6) = 132. The neighbouring Catalan numbers 42 and 429 come from an off-by-one in n, and 6! = 720 counts labelled orderings.

More Coding Interview Problems questions

Exams that ask this topic