IAE Academy

ISRO CS 2023 Q.60: solution and answer

ISRO 2023 · CSQ.60 · 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 → aaSb | T
T → Tb | a

Which of the following statements is true about the language L(G) generated by G?

  1. (A)

    aabbaabb belongs to L(G) but aabb does not

  2. (B)

    aaaaabbb belongs to L(G) but aaaabb does not

  3. (C)

    aaaabb belongs to L(G) but aabbaabb does not

  4. (D)

    aaabb belongs to L(G) but aaaaabbb does not

See the question in the paper

Answer and solution

ANSWER

Option (B): because it has 's and 's, while because it has an even number of 's.

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

  1. From : produces followed by any number of 's, so for every .

  2. From : each use of adds on the left and one on the right. After such uses followed by and , the string is .

  3. Hence . A string is in exactly when all its 's come before all its 's, the number of 's is odd, say , and the number of 's is at least .

  4. Option (a): has 's before 's, so it is not in . The first part of the statement is false, so (a) is false.

  5. Option (b): has , so , and . It is in . has four 's, an even number, so it is not in . Both parts hold, so (b) is true.

  6. Option (c): has an even number of 's, so it is not in . The first part is false, so (c) is false.

  7. Option (d): has , so , and . It is in . But is also in (shown in (b)), so the claim that it does not belong is false. (d) is false.

KEY IDEA

Unroll the grammar to get a closed form. The rule pairs two 's with one , and gives one followed by any number of 's. So , which has an odd number of 's, all 's first, and at least 's.

WATCH OUT FOR

Forgetting the single that contributes, which makes the number of 's odd, not even. Another slip is checking only that the 's are at least half the 's and ignoring order, which wrongly accepts strings like .

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