Open In App

GATE | GATE-CS-2009 | Question 11

Like Article
Like
Save
Share
Report

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:

S -> aSa | bSb | a | b

In this grammar:
S->aSa and S->bSb are the productions that allow the construction of palindromic strings. S-> a and S→ b are the productions that allow the inclusion of single characters.

Considering the structure of the productions, the only way to generate strings is by starting and ending with the same symbol (either “a” or “b”) while having the middle part generated recursively to form a palindrome.

Since the productions S->aSa and S-> bSb only generate strings of odd length, and no production allows for the insertion of additional characters in between to create even-length palindromes.

Hence,The correct option is: All odd length palindromes.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 08 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads