GATE Computer ScienceHardGATE CSE · UGC NET

Consider the grammar S → aSb | bSa | SS | ε. How many strings of length exactly 8 does it generate?

  1. A. 70
  2. B. 56
  3. C. 100
  4. D. 256

Correct answer: A. 70

The grammar generates exactly the strings with equally many a's and b's, so the count is C(8,4) = 70 (confirmed by closure enumeration).

More Theory of Computation questions

Exams that ask this topic