Data Structures & AlgorithmsVery hardAccenture · Infosys OA

Problem: Which best describes the relationship between the number of valid Binary Search Trees on n distinct keys and the Catalan numbers?

  1. A. The count of structurally unique BSTs on n keys is exactly the nth Catalan number, C(n) = (2n choose n)/(n+1)
  2. B. The count equals n! (same as permutations)
  3. C. The count is always a power of 2
  4. D. The count grows linearly with n

Correct answer: A. The count of structurally unique BSTs on n keys is exactly the nth Catalan number, C(n) = (2n choose n)/(n+1)

Choosing each possible root and recursively counting left/right subtree shapes gives the Catalan recurrence C(n) = sum C(i)*C(n-1-i), whose closed form is the nth Catalan number -- the same count that governs balanced-parenthesis sequences.

More Coding Interview Problems questions

Exams that ask this topic