Given the following two languages: \(L_1=\{a^nba^n\;|\;n>0\} \\…
2015
Given the following two languages:
\(L_1=\{a^nba^n\;|\;n>0\} \\ L_2=\{a^nba^nb^{n+1}\;|\;n>0\}\)
Which of the following is correct?
- A.
\( 𝐿_1\)is context free language and\(𝐿_2\)is not context free language - B.
\( 𝐿_1\)is not context free language and\(𝐿_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 65 students.
Show answer & explanation
Correct answer: A
Final answer: L1 is a context-free language and L2 is not a context-free language.
L1 (context-free): A simple context-free grammar that generates L1 = { a^n b a^n | n>0 } is
S -> a S a | a b a
This grammar produces exactly strings with equal numbers of a's on both sides of a single central b, so L1 is context-free.
L2 (not context-free): Sketch using the pumping lemma for context-free languages:
Assume L2 were context-free. Let p be the pumping length from the lemma and consider the string s = a^p b a^p b^{p+1} in L2.
The pumping lemma gives a decomposition s = u v x y z with |v x y| ≤ p and |v y| > 0, and u v^i x y^i z ∈ L2 for all i ≥ 0.
Because |v x y| ≤ p, the substring v x y lies entirely within one of these regions of s: the first block of a's, the middle part around the single central b and nearby a's, or the final block of b's.
Pumping cases (why each leads to a contradiction):
If v and y lie entirely inside the first a-block or inside the second a-block, pumping changes the number of a's on only one side of the central b. That breaks the required equality between the two a-blocks, so for some i the pumped string is not in L2.
If v and y lie entirely inside the final block of b's, pumping changes the number of trailing b's while leaving the a-block counts tied to the original p, so the required relation trailing b count = left/right a-count + 1 fails for some i.
If v and y span the boundary that includes the single middle b and adjacent a's, pumping changes the local composition around the center in a way that cannot maintain both equal a-block lengths and the trailing b count relation simultaneously. Thus some pumped string will not belong to L2.
In every possible placement of v and y, pumping produces a string not in L2 for some i, contradicting the pumping lemma. Hence L2 is not context-free.
Conclusion: L1 is context-free (a simple CFG exists) and L2 is not context-free (pumping-lemma contradiction).
A video solution is available for this question — log in and enroll to watch it.