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
- AStrings that begin and end with the same symbol
- BAll odd and even length palindromes
- CAll odd length palindromesCorrect answer
- DAll 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.