Consider the following context-free grammars: G1: S → aS | B, B → b | bB G2: S → aA | bB, A → aA | B | , B → bB | Which one of the following pairs of languages is generated by G1 and G2, respectively?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2016 Set 1 · Q42
Time
Select one answerSingle correct
Solution
Official answer: D) {am bn | m ≥ 0 and n > 0} and {am bn | m > 0 or n > 0}
Context-Free Grammars and PDAsLet us analyze the languages generated by each grammar:
Grammar :
The variable generates one or more 's: . The start variable generates zero or more 's followed by a string from : .
Grammar :
generates zero or more 's: . generates zero or more 's followed by : . Then for the start variable :
Through branch : strings of the form .
Through branch : strings of the form .
Taking the union:
(i.e., all strings of the form where at least one of is strictly greater than 0).
Matching these gives:
This matches option (D).
Try the question first, then check your work.
Examiner trap
Derive the regular expressions for the non-terminals: for , must produce at least one , while for , ensures at least one , and ensures at least one .
This Context-Free Grammars and PDAs previous year question is Q42 of the GATE CSE 2016 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 2016 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.