GateAI
Context-Free Grammars and PDAs

GATE CSE 2017 Set 1 · Q34

MCQ2 marksEasy

Time

If GG is a grammar with productions S→SaS∣aSb∣bSa∣SS∣ϵS \rightarrow SaS \mid aSb \mid bSa \mid SS \mid \epsilon where SS is the start variable, then which one of the following strings is not generated by GG?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) babba

Context-Free Grammars and PDAs

Let na(w)n_a(w) and nb(w)n_b(w) denote the number of occurrences of 'a' and 'b' in string ww, respectively.

Analyzing each production of the grammar:

  • S→SaSS \rightarrow SaS: introduces one 'a' and zero 'b' (na−nbn_a - n_b increases by 1)

  • S→aSbS \rightarrow aSb: introduces one 'a' and one 'b' (na−nbn_a - n_b unchanged)

  • S→bSaS \rightarrow bSa: introduces one 'a' and one 'b' (na−nbn_a - n_b unchanged)

  • S→SSS \rightarrow SS: concatenation of two valid strings

  • S→ϵS \rightarrow \epsilon: terminal step with zero terminals (na−nb=0n_a - n_b = 0)

Therefore, every string ww generated by this grammar must satisfy the property:

na(w)≥nb(w)n_a(w) \ge n_b(w)

Checking the options:

  • A. abababab: na=2,nb=2  ⟹  na≥nbn_a = 2, n_b = 2 \implies n_a \ge n_b (can be generated)

  • B. aaabaaab: na=3,nb=1  ⟹  na≥nbn_a = 3, n_b = 1 \implies n_a \ge n_b (can be generated)

  • C. abbaaabbaa: na=3,nb=2  ⟹  na≥nbn_a = 3, n_b = 2 \implies n_a \ge n_b (can be generated)

  • D. babbababba: na=2,nb=3  ⟹  na<nbn_a = 2, n_b = 3 \implies n_a < n_b (cannot be generated)

Hence, the string babba cannot be generated by GG, making D the correct answer.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

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 in GATE CSE

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 PDAs

More from GATE CSE 2017 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 1 · Q34 · MCQ

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.