Which of the following languages are context-free? \(L_1 = \{a^mb^n a^n b^m |…
2015
Which of the following languages are context-free?
\(L_1 = \{a^mb^n a^n b^m | m, n ≥ 1 \}\)
\(L_2 = \{a^mb^n a^mb^n | m, n ≥ 1\}\)
\(L_3 = \{a^mb^n | m = 2n + 1 \}\)
- A.
\(L_1\)and\(L_2\)only - B.
\(L_1\)and\(L_3\)only - C.
\(L_2\)and\(L_3\)only - D.
\(L_3\)only
Attempted by 102 students.
Show answer & explanation
Correct answer: B
Key insight: context-free grammars can enforce one equality between counts (like a^n b^n) but cannot generally copy two independent numbers at once.
L1 = { a^m b^n a^n b^m | m, n ≥ 1 } is context-free.
Reason/grammar (sketch): build the matching outer a^m and b^m while generating the middle b^n a^n.
One grammar that works:
S -> a S b | a T b
T -> b T a | b a
L2 = { a^m b^n a^m b^n | m, n ≥ 1 } is NOT context-free.
Reason (sketch): this language requires duplicating two independent counts (both the a-block and the b-block of the first half must be copied exactly in the second half). Context-free grammars can enforce a single equality like a^k b^k, but cannot simultaneously enforce two independent equalities. Using the pumping lemma for context-free languages or Ogden's lemma on the string a^p b^p a^p b^p gives a contradiction, because any allowed pumping changes only part of the four-block structure and breaks the required equalities.
L3 = { a^m b^n | m = 2n + 1 } is context-free.
Reason/grammar (sketch): m is determined by n, so produce two a's for each b plus a base a.
One grammar that works:
S -> a | aa S b
Conclusion: The context-free languages among the three are L1 and L3.
A video solution is available for this question — log in and enroll to watch it.