Consider the following languages: \(L_1 = \{ a^{n+m} b^n a^m \mid n, m \geq 0…
2018
Consider the following languages:
\(L_1 = \{ a^{n+m} b^n a^m \mid n, m \geq 0 \} \\ L_2 = \{ a^{n+m} b^{n+m} a^{n+m} \mid n, m \geq 0\} \)
Which of the following is correct ?
\(Code:\)
- A.
Only
\(𝐿_1\)is context free language - B.
Only
\(𝐿_2\)is context free language - C.
Both
\(𝐿_1\)and\(𝐿_2\)are context free languages - D.
Both
\(𝐿_1\)and\(𝐿_2\)are not context free languages
Attempted by 72 students.
Show answer & explanation
Correct answer: A
Final conclusion: Only L1 is a context-free language; L2 is not.
Reasoning for L1 (constructive):
Rewrite a typical string in L1 as a^m a^n b^n a^m = a^m (a^n b^n) a^m, where m,n ≥ 0.
A context-free grammar that generates L1 is:
S -> X | a S a
X -> a X b | ε
Intuition: X generates a^n b^n, and the production S -> a S a wraps matching a's around that block, producing a^m (a^n b^n) a^m.
Reasoning for L2 (non-context-free):
Observe that for any k ≥ 0 we can choose n = k, m = 0, so L2 contains every string a^k b^k a^k. Conversely, any string in L2 has length parameters n,m with n+m = k, so L2 = { a^k b^k a^k | k ≥ 0 }.
The language { a^k b^k a^k | k ≥ 0 } is a standard example of a non-context-free language (it cannot be generated by any context-free grammar).
Sketch of a pumping-lemma style argument: assume { a^k b^k a^k } is context-free with pumping length p, take s = a^p b^p a^p. Any valid decomposition required by the pumping lemma places the pumped portion inside at most two adjacent blocks; pumping changes counts so that after pumping some block counts differ, producing a string not of the form a^k b^k a^k, a contradiction. Hence the language is not context-free.
Therefore the correct choice is the statement that only L1 is context-free and L2 is not.
A video solution is available for this question — log in and enroll to watch it.