GateAI
Context-Free Grammars and PDAs

GATE CSE 2016 Set 1 · Q42

MCQ2 marksMedium

Time

Consider the following context-free grammars: G1:S→aS∣B,B→b∣bBG_1: S \to aS | B, B \to b | bB G2:S→aA∣bB,A→aA∣B∣ε,B→bB∣εG_2: S \to aA | bB, A \to aA | B | \varepsilon, B \to bB | \varepsilon Which one of the following pairs of languages is generated by G1G_1 and G2G_2, respectively?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) {am bn | m ≥ 0 and n > 0} and {am bn | m > 0 or n > 0}

Context-Free Grammars and PDAs

Let us analyze the languages generated by each grammar:

  1. Grammar G1G_1:

    • S→aS∣BS \to aS \mid B

    • B→b∣bBB \to b \mid bB

    The variable BB generates one or more bb's: L(B)=b+={bn∣n>0}L(B) = b^+ = \{b^n \mid n > 0\}. The start variable SS generates zero or more aa's followed by a string from BB: L(G1)=a∗b+={ambn∣m≥0 and n>0}L(G_1) = a^* b^+ = \{a^m b^n \mid m \ge 0 \text{ and } n > 0\}.

  2. Grammar G2G_2:

    • S→aA∣bBS \to aA \mid bB

    • A→aA∣B∣εA \to aA \mid B \mid \varepsilon

    • B→bB∣εB \to bB \mid \varepsilon

    BB generates zero or more bb's: L(B)=b∗L(B) = b^*. AA generates zero or more aa's followed by BB: L(A)=a∗b∗L(A) = a^* b^*. Then for the start variable SS:

    • Through branch S→aAS \to aA: strings of the form aa∗b∗=a+b∗={ambn∣m>0 and n≥0}a a^* b^* = a^+ b^* = \{a^m b^n \mid m > 0 \text{ and } n \ge 0\}.

    • Through branch S→bBS \to bB: strings of the form bb∗=b+={a0bn∣n>0}b b^* = b^+ = \{a^0 b^n \mid n > 0\}.

    Taking the union:

    L(G2)=(a+b∗)∪(b+)={ambn∣m>0 or n>0}L(G_2) = (a^+ b^*) \cup (b^+) = \{a^m b^n \mid m > 0 \text{ or } n > 0\}

    (i.e., all strings of the form ambna^m b^n where at least one of m,nm, n is strictly greater than 0).

Matching these gives:

  • L(G1)={ambn∣m≥0 and n>0}L(G_1) = \{a^m b^n \mid m \ge 0 \text{ and } n > 0\}

  • L(G2)={ambn∣m>0 or n>0}L(G_2) = \{a^m b^n \mid m > 0 \text{ or } n > 0\}

This matches option (D).

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 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

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 2016 Set 1 has 3.

How GATE tests Context-Free Grammars and PDAs

More from GATE CSE 2016 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2016 Set 1 · Q42 · MCQ

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

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