GATE Computer ScienceModerateGATE CS (PYQ pattern)

How many strings of length at most 6 are generated by S → aSa | bSb | aa | b?

  1. A. 14
  2. B. 28
  3. C. 15
  4. D. 12

Correct answer: A. 14

Every string is a palindrome whose centre is b (odd lengths) or aa (even lengths), with free outer halves. Length 1: b; 2: aa; 3: 2; 4: 2; 5: 4; 6: 4. Total 1 + 1 + 2 + 2 + 4 + 4 = 14 (ε is not generated; 28 counts every non-empty palindrome up to length 6, ignoring the fixed centres).

More Theory of Computation questions

Exams that ask this topic