GATE Computer ScienceModerateGATE CSE · ISRO

Consider the grammar S → aSa | bSb | a | b | ε. How many strings of length exactly 7 does it generate?

  1. A. 32
  2. B. 8
  3. C. 16
  4. D. 24

Correct answer: C. 16

The grammar generates all palindromes over {a, b}; a palindrome of length 7 is fixed by its first 4 symbols, giving 2⁴ = 16.

More Theory of Computation questions

Exams that ask this topic