GateAI
Context-Free Grammars and PDAs

GATE CSE 2026 Set 1 · Q25

MSQ1 markMedium

Time

Consider the following grammar where SS is the start symbol, and aa and bb are terminal symbols. S→aSbS∣bS∣ϵS \rightarrow aSbS \mid bS \mid \epsilon Which of the following statements is/are true?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: A) The grammar is ambiguous; B) The string abb has two distinct derivations in this grammar; C) The string abab has only one rightmost derivation

Context-Free Grammars and PDAs

Let us analyze each statement based on the grammar S→aSbS∣bS∣ϵS \to aSbS \mid bS \mid \epsilon:

  1. Ambiguity and Derivations for abbabb (Statements A and B): Consider the string w=abbw = abb:

    • Derivation 1:

      S⇒aSbS⇒a(bS)bS⇒ab(ϵ)b(ϵ)=abbS \Rightarrow aSbS \Rightarrow a(bS)bS \Rightarrow ab(\epsilon)b(\epsilon) = abb
    • Derivation 2:

      S⇒aSbS⇒a(ϵ)bS⇒ab(bS)⇒abb(ϵ)=abbS \Rightarrow aSbS \Rightarrow a(\epsilon)bS \Rightarrow ab(bS) \Rightarrow abb(\epsilon) = abb

    Because there exist two distinct parse trees (and therefore two distinct leftmost/rightmost derivations) for the string abbabb, the string abbabb has two distinct derivations and the grammar is ambiguous. Hence, (A) and (B) are true.

  2. Derivation for abababab (Statement C): Let us find the rightmost derivation for w=ababw = abab:

    S⇒aSbS⇒aSb(aSbS)⇒aSb(aSbϵ)⇒aSb(aϵb)⇒a(ϵ)bab=ababS \Rightarrow aSbS \Rightarrow aSb(aSbS) \Rightarrow aSb(aSb\epsilon) \Rightarrow aSb(a\epsilon b) \Rightarrow a(\epsilon)bab = abab

    There is no other valid derivation sequence to generate abababab. Since it produces a unique parse tree, abababab has only one rightmost derivation. Thus, (C) is true.

  3. Decidability (Statement D): The language generated by this context-free grammar is a context-free language (CFL). All context-free languages are decidable. Therefore, statement (D) is false.

Hence, the correct statements are A, B, and C.

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 Q25 of the GATE CSE 2026 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. 2 of them are 1-mark MSQs like this one, and GATE CSE 2026 Set 1 has 2.

How GATE tests Context-Free Grammars and PDAs

More from GATE CSE 2026 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2026 Set 1 · Q25 · MSQ

Consider the following grammar where S is the start symbol, and a and b are terminal symbols. S → aSbS bS Which of the following statements is/are true?

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.