GATE Computer ScienceModerateGATE CSE

The grammar S → aSb | SS | ab generates how many distinct strings of length 6?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

It generates the non-empty balanced bracket strings (a = open, b = close); length 6 corresponds to Catalan(3) = 5 strings.

More Theory of Computation questions

Exams that ask this topic