GATE / CS ARCHIVE

GATE CSE 2009 / QUESTION 12

Odd-palindrome grammar

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2009 paper

GATE 2009, Q12 1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 12, GATE 2009: For grammar S→aSa|bSb|a|b over {a, b}, identify the language: A all palindromes; B odd-length palindromes; C all strings beginning and ending with the same symbol; D even-length palindromes.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

The base productions produce a single a or b. Every recursive production adds the same symbol at both ends, preserving the palindrome property and odd length. Conversely strip matching outer pairs from any odd palindrome until one central symbol remains, yielding a derivation. Thus exactly all odd-length palindromes, B.

Every derivation starts from a one-symbol base a or b and adds matching symbols around the outside. Length therefore remains odd and the string remains a palindrome. Conversely, removing the equal end symbols from any odd palindrome repeatedly reaches its one-symbol centre, giving a reverse derivation. Even palindromes are excluded because no ε base exists; a string such as aabba begins/ends alike but is not generated.

Original paper, page 3