IAE Academy

ISRO CS 2023 Q.57: solution and answer

ISRO 2023 · CSQ.57 · 1 mark · MCQ

Consider the context-free grammar G below. Here S is the starting non-terminal symbol, while a and b are terminal symbols.

S → aSb | T
T → bT | b

The language generated by G is:

  1. (A)

    {a^m b^n : 0 ≤ m < n}

  2. (B)

    {a^m b^n : 0 < m < n}

  3. (C)

    {a^m b^n : 0 < n ≤ m}

  4. (D)

    {a^n b^n : 0 ≤ n}

See the question in the paper

Answer and solution

ANSWER

The grammar generates , option (a).

Official answer: ASource: ISRO's revised and final answer key of 16 February 2024

  1. Start with . The rules give for every . The only way to stop is , so at least one is always produced.

  2. Now consider . Using exactly times () puts one on the left and one on the right each time, giving .

  3. Finish with and with . The string is .

  4. Put . Since , we get , that is , with . The case is directly, giving with . Conversely, every pair with is obtained by taking .

  5. So , which is option (a).

  6. Option (b) forces , which wrongly excludes strings such as and . Option (c) requires at least as many 's as... no: it requires , so no more 's than 's, but every string of has strictly more 's than 's. Option (d) needs equal numbers, but the last step always leaves at least one extra .

KEY IDEA

Split the grammar into its two parts. generates with , and wraps it with matching pairs of and . So the number of 's exceeds the number of 's by exactly .

WATCH OUT FOR

Choosing (d) because the rule looks like , or choosing (b) by forgetting that directly gives strings with no at all.

From the ISRO CS 2023 paper. Every question of this paper · The full paper (PDF, ISRO) · All 6 ISRO CFG & PDA questions, with notes

More ISRO CFG & PDA questions