If G is a grammar with productions S → SaS aSb bSa SS where S is the start variable, then which one of the following strings is not generated by G?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2017 Set 1 · Q34
Time
Select one answerSingle correct
Solution
Official answer: D) babba
Context-Free Grammars and PDAsLet and denote the number of occurrences of 'a' and 'b' in string , respectively.
Analyzing each production of the grammar:
: introduces one 'a' and zero 'b' ( increases by 1)
: introduces one 'a' and one 'b' ( unchanged)
: introduces one 'a' and one 'b' ( unchanged)
: concatenation of two valid strings
: terminal step with zero terminals ()
Therefore, every string generated by this grammar must satisfy the property:
Checking the options:
A. : (can be generated)
B. : (can be generated)
C. : (can be generated)
D. : (cannot be generated)
Hence, the string babba cannot be generated by , making D the correct answer.
Try the question first, then check your work.
Examiner trap
Observe how each production changes the count of terminal 'a's compared to terminal 'b's. Can any production produce more 'b's than 'a's?
This Context-Free Grammars and PDAs previous year question is Q34 of the GATE CSE 2017 Set 1 paper. Find more GATE CSE PYQs on Context-Free Grammars and PDAs in Theory of Computation, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Context-Free Grammars and PDAs PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Context-Free Grammars and PDAs has 26 GATE CSE PYQs across 17 papers from 2011 to 2026. 9 of them are 2-mark MCQs like this one, and GATE CSE 2017 Set 1 has 3.
How GATE tests Context-Free Grammars and PDAsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.