Skip to content

ISRO Scientist/Engineer CSE 2020Theory of Computation › Regular and Context-Free Languages

ISRO Scientist/Engineer CSE 2020 PYQ: The language which is generated by the grammar $S \rightarrow aSa \mid bSb \mid a \mid b$ over the alphabet…

The language which is generated by the grammar $S \rightarrow aSa \mid bSb \mid a \mid b$ over the alphabet of $\{a,b\}$ is the set of

  1. A
    Strings that begin and end with the same symbol
  2. B
    All odd and even length palindromes
  3. C
    All odd length palindromes
    Correct answer
  4. D
    All even length palindromes

Answer

(C) All odd length palindromes

Approach

The grammar S → aSa | bSb | a | b generates palindromes by wrapping a smaller palindrome with matching symbols, with base cases being single characters. This construction always produces strings of odd length, and every odd-length palindrome over {a,b} can be generated. Thus the language is exactly the set of all odd-length palindromes.

Reviewed by ISRO IQ Editorial Team.