GATE | GATE-CS-2009 | Question 11

S -> aSa|bSb|a|b; The language generated by the above grammar over the alphabet {a,b} is the set of
(A) All palindromes
(B) All odd length palindromes.
(C) Strings that begin and end with the same symbol
(D) All even length palindromes

Answer: (B)

Explanation: The possible palindrome generated by above grammar can be of odd length only as there is no rule for S -> \epsilon

For example generated palindromes are aba, aaa, bab, ababa, aaaaa, ..

Quiz of this Question

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:

0 Average Difficulty : 0/5.0
No votes yet.