IAE Academy

GATE 2026 CS1 Q.52: solution and answer

GATE 2026 · CS1Q.52 · 2 marks · MSQ

Consider the following context-free grammar .

In the above grammar, is the start symbol, and are terminal symbols, and and are non-terminal symbols.

Let be the language generated by the grammar . For a string , let be the number of 's in and be the number of 's in .

Which of the following statements is/are true?

  1. (A)

    There is a string such that

  2. (B)

    For every string ,

  3. (C)

    There is a string such that

  4. (D)

    For every string ,

See the question in the paper

Answer and solution

ANSWER

(B) and (D) are true. (A) and (C) are false.

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

  1. Let for a derived string . The grammar is context-free and is additive over concatenation, so we can compute for each non-terminal separately.

  2. generates exactly with . So and always contributes at least one .

  3. : the terminals contribute 3 a's and 2 b's, so plus . This gives and at least b's.

  4. : the terminals contribute . The two 's contribute and add at least 2 b's. Using this rule times and then gives and .

  5. contains TWO copies of . The terminals give and give , and . So with uses of the recursive rule in the two copies, .

  6. Hence for every . So always: (A) is false and (B) is true.

  7. Count the b's. The b's come from (1), (2), the middle (at least 1), and the two 's (at least and ). So .

  8. Put . Then and , so for every . Therefore for every string: (D) is true and (C) is false.

  9. Check on the smallest string: everywhere and in both copies. Then and , so and . This agrees with the above.

KEY IDEA

Track the difference for each non-terminal. gives , each gives , and has two copies of , so the difference is at least 2. The b-count grows at least three times as fast as the difference, which gives .

WATCH OUT FOR

Treating as if it had only one . It has two. Dropping one gives the wrong string counts, such as and for the smallest string. The correct smallest string has and . The conclusions (B) and (D) still hold.

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