Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

GATE | GATE-CS-2007 | Question 78

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Consider the CFG with {S,A,B) as the non-terminal alphabet, {a,b) as the terminal alphabet, S as the start symbol and the following set of production rules

S --> aB        S --> bA
B --> b         A --> a
B --> bS        A --> aS
B --> aBB       A --> bAA

Which of the following strings is generated by the grammar?
(A) aaaabb
(B) aabbbb
(C) aabbab
(D) abbbba


Answer: (C)

Explanation: Given below production rules.

S --> aB        S --> bA
B --> b         A --> a
B --> bS        A --> aS
B --> aBB       A --> bAA

We can derive aabbab using below sequence

S  -> aB      [Using S --> aB] 
   -> aaBB    [Using B --> aBB]
   -> aabB    [Using B --> b]
   -> aabbS   [Using B --> bS]
   -> aabbaB  [Using S --> aB]
   -> aabbab  [Using B --> b]



Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 14 Sep, 2021
Like Article
Save Article
Similar Reads