GATE Computer ScienceHardGATE CS (PYQ pattern)

The grammar S → aSb | bSa | SS | ε generates how many strings of length exactly 8?

  1. A. 70
  2. B. 14
  3. C. 35
  4. D. 140

Correct answer: A. 70

Surprisingly it generates every string with equally many a's and b's, so the count is C(8,4) = 70. The Catalan number 14 would count only Dyck-type strings.

More Theory of Computation questions

Exams that ask this topic