Consider the language \(L = \{ a^n b^{n-3} \mid n > 2 \}\) on \(Ξ£=\{π‘Ž,𝑏\}\).…

2019

Consider the languageΒ \(L = \{ a^n b^{n-3} \mid n > 2 \}\) onΒ \(Ξ£=\{π‘Ž,𝑏\}\). Which one of the following grammars generates the languageΒ \(𝐿\)?

  1. A.

    π‘†β†’π‘Žπ΄βˆ£π‘Ž,π΄β†’π‘Žπ΄π‘βˆ£π‘

  2. B.

    π‘†β†’π‘Žπ‘Žπ΄βˆ£πœ†,π΄β†’π‘Žπ΄π‘βˆ£πœ†

  3. C.

    π‘†β†’π‘Žπ‘Žπ‘Žπ΄βˆ£π‘Ž,π΄β†’π‘Žπ΄π‘βˆ£πœ†

  4. D.

    π‘†β†’π‘Žπ‘Žπ‘Žπ΄,π΄β†’π‘Žπ΄π‘βˆ£πœ†\

Attempted by 49 students.

Show answer & explanation

Correct answer: D

Answer: The grammar S β†’ a a a A , A β†’ a A b | Ξ» generates the language.

Reasoning:

  • Base case: If A β†’ Ξ», then S β†’ a a a A β†’ a a a, giving a^3 b^0 which matches the form a^n b^{n-3} with n = 3.

  • Induction/iteration: Each application of A β†’ a A b inserts one additional a and one additional b. After k applications of that production followed by A β†’ Ξ», we get S β‡’ a a a (a^k b^k) = a^{3+k} b^{k}.

  • Set n = 3 + k (with k β‰₯ 0). Then the derived string is a^{n} b^{n-3}, and because k β‰₯ 0 we have n > 2. Thus every string produced by the grammar is in L.

  • Conversely, any string in L has the form a^{n} b^{n-3} with n > 2. Writing k = n - 3 (so k β‰₯ 0), that string equals a^{3+k} b^{k}, which the grammar produces by k iterations of A β†’ a A b followed by A β†’ Ξ». Hence the grammar generates exactly L.

Why the other grammars fail:

  • Grammar with productions S β†’ a A | a and A β†’ a A b | b produces the single terminal 'a' and otherwise yields strings with equal numbers of a's and b's (or variants), so it does not enforce three more a's than b's.

  • Grammar with productions S β†’ a a A | Ξ» and A β†’ a A b | Ξ» allows the empty string and produces a^{2+k} b^{k}, giving two more a's than b's instead of three, so it does not match L.

  • Grammar with productions S β†’ a a a A | a and A β†’ a A b | Ξ» has the correct main branch but also allows the single 'a', which is not in L, so it is not an exact description of the language.

Therefore the correct grammar is S β†’ a a a A , A β†’ a A b | Ξ» because it generates exactly all strings of the form a^{n} b^{n-3} with n > 2.

A video solution is available for this question β€” log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor