Computer Science EngineeringHard

The grammar S -> aSa | bSb | a | b | epsilon generates

  1. A. strings with equal numbers of a's and b's
  2. B. strings of even length
  3. C. strings that start and end with the same letter
  4. D. all palindromes over {a, b}

Correct answer: D. all palindromes over {a, b}

The productions build a string symmetrically around an optional middle symbol, which yields exactly the palindromes.

More Theory of Computation, Compilers & Digital Logic (ISRO CS) questions

Exams that ask this topic