IAE Academy

GATE 2026 CS1 Q.25: solution and answer

GATE 2026 · CS1Q.25 · 1 mark · MSQ

Consider the following grammar where is the start symbol, and and are terminal symbols.

Which of the following statements is/are true?

  1. (A)

    The grammar is ambiguous

  2. (B)

    The string has two distinct derivations in this grammar

  3. (C)

    The string has only one rightmost derivation

  4. (D)

    The language generated by the grammar is undecidable

See the question in the paper

Answer and solution

ANSWER

(A), (B) and (C) are true. The string abb has two parse trees, so the grammar is ambiguous. The string abab has only one parse tree, so it has only one rightmost derivation. The language is context-free, so it is decidable, which makes (D) false.

Official answer: A, B, CSource: Official answer key, GATE 2026 CS1 (IIT Guwahati)

  1. The grammar is . A nonempty string that starts with can only come from . A string that starts with can only come from , which splits it as , where and are both strings that derives. Because can produce extra 's anywhere, may itself contain unmatched 's. So the written in is not forced to be one particular of .

  2. Option (B), the string . It starts with , so the first step is , and we need . There are two splits, and both work. Split 1: , (from ). Split 2: (from ), .

  3. These give two different leftmost derivations of : In the first, the inner goes to and the last produces the second . In the second, the inner produces the first and the last goes to . The parse trees are different, so has two distinct derivations. (B) is true.

  4. Option (A). A grammar is ambiguous if some string has two different parse trees (equivalently, two leftmost derivations). By step 3, is such a string, so the grammar is ambiguous. (A) is true.

  5. Option (C), the string . It starts with , so and we need . The of the production is either the 1st or the 3rd symbol of . If it is the 3rd, then . But cannot derive : after the rest would be , and every that produces comes from , which always puts a after it. So the must be the 1st symbol: , .

  6. Now starts with , so with , which forces . Every choice is forced, so has exactly one parse tree. A parse tree gives exactly one rightmost derivation: So has only one rightmost derivation. (C) is true.

  7. Option (D). The language is generated by a context-free grammar, so it is context-free. Every context-free language is decidable: the CYK algorithm decides membership for any string. (D) is false.

  8. The true statements are (A), (B) and (C).

KEY IDEA

In , the written in the production does not have to be the first that closes the . The production lets the inner soak up extra 's. So whenever several 's follow an , check whether more than one of them can play the part of that . In two can, which gives two parse trees. In only one can, because cannot derive .

WATCH OUT FOR

Treating like the balanced-parentheses grammar , which is unambiguous, and so assuming the in the production must be the first that balances the . Adding breaks this: in , either can be the matching one. A second slip is to answer (D) as true or uncertain. Every context-free language is decidable.

From the GATE 2026 CS1 paper. Every question of this paper · Download the full paper · All 9 CFG & PDA questions, with notes

More CFG & PDA questions