For a string \(w\), we define \(w^R\) to be the reverse of \(w\). For example,…
2021
For a string \(w\), we define \(w^R\) to be the reverse of \(w\). For example, if \(w = 01101\) then \(w^R = 10110\) .
Which of the following languages is/are context-free?
- A.
\(\{ wxw^Rx^R \mid w,x \in \{0,1\} ^* \}\) - B.
\(\{ ww^Rxx^R \mid w,x \in \{0,1\} ^* \}\) - C.
\(\{ wxw^R \mid w,x \in \{0,1\} ^* \}\) - D.
\(\{ wxx^Rw^R \mid w,x \in \{0,1\} ^* \}\)
Attempted by 82 students.
Show answer & explanation
Correct answer: B, C, D
Summary: All four given languages are context-free. Below are short justifications or grammars for each.
{ w x w^R x^R | w,x ∈ {0,1}* }: This equals { y y^R | y ∈ {0,1}* } (take y = w x), the set of even-length palindromes. A simple CFG is S -> ε | 0 S 0 | 1 S 1, so it is context-free.
{ w w^R x x^R | w,x ∈ {0,1}* }: This is the concatenation of two languages of the form {z z^R}. Each {z z^R} is context-free (same CFG as above), and CFLs are closed under concatenation, so this language is context-free.
{ w x w^R | w,x ∈ {0,1}* }: Generate the arbitrary middle x and then wrap matching symbols for w. For example, grammar: S -> T | 0 S 0 | 1 S 1 and T -> ε | 0 T | 1 T. This produces exactly strings of the form w x w^R, hence context-free.
{ w x x^R w^R | w,x ∈ {0,1}* }: The middle x x^R is an even palindrome; generate it first and then symmetrically wrap w and w^R. For example, let M -> ε | 0 M 0 | 1 M 1 (generates x x^R), and S -> M | 0 S 0 | 1 S 1. This CFG yields all strings of the given form, so the language is context-free.
Conclusion: Each language can be described by a context-free grammar (or obtained by CFL closure operations), so all four languages are context-free.
A video solution is available for this question — log in and enroll to watch it.