Which one of the following languages over Σ = {𝑎, 𝑏} is NOT context-free?
2019
Which one of the following languages over Σ = {𝑎, 𝑏} is NOT context-free?
- A.
\(\{ww^R \mid w \in \{a, b\}^*\}\) - B.
\(\{wa^nb^nw^R \mid w \in \{a,b\}^*, n \geq 0\}\) - C.
\(\{wa^nw^Rb^n \mid w \in \{a,b\}^* , n \geq 0\}\) - D.
\(\{ a^nb^i \mid i \in \{n, 3n, 5n\}, n \geq 0\}\)
Attempted by 98 students.
Show answer & explanation
Correct answer: C
Final answer: The language {wa^n w^R b^n | w ∈ {a,b}*, n ≥ 0} is NOT context-free.
Explanations for each language:
{ww^R | w ∈ {a,b}*}: Context-free. A PDA can nondeterministically guess the midpoint, push the first half, and then pop to match the second half; equivalently palindromes have a context-free grammar.
{w a^n b^n w^R | w ∈ {a,b}*, n ≥ 0}: Context-free. For example, let A -> a A b | ε (A generates a^n b^n) and S -> A | a S a | b S b. S wraps matching letters around the central A, producing strings of the required form.
{w a^n w^R b^n | w ∈ {a,b}*, n ≥ 0}: Not context-free. Intuition: to accept such strings a pushdown automaton would need to both match the outer palindrome-like pair w and w^R and independently verify that the number of a’s in the middle equals the number of trailing b’s. Those are two separate, interleaved dependencies that a single stack cannot enforce simultaneously. Formally, one proves non-context-freeness by applying a standard CFL tool (for example, the pumping lemma for CFLs or closure under intersection with a suitable regular language followed by a homomorphism) to derive a contradiction with a known non-context-free language. Hence this language is not context-free.
{a^n b^i | i ∈ {n,3n,5n}, n ≥ 0}: Context-free. This is the union of {a^n b^n}, {a^n b^{3n}}, and {a^n b^{5n}.} For fixed k, {a^n b^{k n}} is generated by S -> ε | a S b^k, and a finite union of CFLs is CFL.
Conclusion: The only non-context-free language among the four is {w a^n w^R b^n | w ∈ {a,b}*, n ≥ 0}.
A video solution is available for this question — log in and enroll to watch it.