retagged by
7,212 views
27 votes
27 votes

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?

  1. $\{ wxw^Rx^R \mid w,x \in \{0,1\} ^* \}$
  2. $\{ ww^Rxx^R \mid w,x \in \{0,1\} ^* \}$
  3. $\{ wxw^R \mid w,x \in \{0,1\} ^* \}$
  4. $\{ wxx^Rw^R \mid w,x \in \{0,1\} ^* \}$
retagged by

2 Answers

Best answer
24 votes
24 votes

In all the options, $w,x \in \{ 0,1 \}^*.$

Option B :

$ww^Rxx^R$ is CFL because $ww^R$ is CFL and $xx^R$ is CFL and we know concatenation of two CFL is CFL.

CFG for $ww^Rxx^R :$

$S \rightarrow AB $

$A \rightarrow 0A0 \mid 1A1 \mid \epsilon$    ; (A will produce $ww^R$ )

$B \rightarrow 0B0 \mid 1B1 \mid \epsilon$  ; (B will produce $xx^R$ )

We can also write CFG in simple manner as following :

$S \rightarrow AA $  (NOTE that both A will produce palindrome strings which may not be same)

$A \rightarrow 0A0 \mid 1A1 \mid \epsilon$    ; (A will produce $ww^R$ )


Option C :

$wxw^R$ is $\Sigma^*$ because every string $u$ can be written as $wxw^R$ by taking $w = \epsilon$ and $u = x$

Every regular language is CFL, so, Option C is CFL.


Option D :

$wxx^Rw^R$ is basically $uu^R ; u \in \{0,1 \}^*$. 

Claim 1 :

Every string of the form $wxx^Rw^R$ is basically even length palindrome :

Proof :

Let $w = a_1a_2a_3 ; x = b_1b_2$ then $wxx^Rw^R = a_1a_2a_3 b_1b_2 b_2 b_1 a_3a_2a_1$ is even length palindrome $uu^R$ where  $u = a_1a_2a_3 b_1b_2 $

Claim 2 :

Every even length palindrome $uu^R$ can be written as $wxx^Rw^R.$

Proof :

Take $x = \in .$ That’s it.

So,  

$wxx^Rw^R$ is basically $uu^R ; u \in \{0,1 \}^*$ which is well known CFL.

CFG for $uu^R ; u \in \{0,1 \}^* :$

$A \rightarrow 0A0 \mid 1A1 \mid \in$    ; (A will produce $uu^R$ )


Option A :

$L = wxw^Rx^R$ is Not CFL. We can prove it by using pumping lemma for CFLs. 

Assume L is CFL then we have pumping length P. 

Assume P is the pumping length for $L.$ Take string  $W = 0^P 1^P0^P1^P$ in $L.$ Since $|u| \geq P,$ so we should be able to pump it somehow. But whatever correct decomposition/split $uvxyz$ of $W$ we take, when we do raise $v,y$ to the power zero, the resulting string will no longer belong to the language $L.$ So we have contradiction, hence, $L$ is Not CFL.

This is correct formal argument for $L$ to be Non CFL and more examples to understand “Pumping lemma of CFL or regular languages” can be found in my answers in my profile. So, anyone who want to learn, can practice from there. 

Informal and vague Idea of $L = wxw^Rx^R$ being Non-CFL is as follows :

We need to store $w$ in stack so that we can compare it with $w^R$ in future. So, we push $w$ on stack. We need to store $x$ in stack so that we can compare it with $x^R$ in future. So, we push $x$ on stack. So, after scanning substring/prefix $wx$ , our stack has $x$ on top of $w$ in the stack. Now, we need to match $w^R$ with $w$ but on top of the stack we have $x$, so we cannot match $w^R$ with $w.$ So, PDA can not accept this language. 

selected by
7 votes
7 votes
Option A: Not context free, we have to match $w$ with $w^R$ but the top of the stack contains $x$, so not possible.

Option B: Context free, first match $w$ with $w^R$ and then $x$ with $x^R$ using stack.

Option C: Context free, it is just $\Sigma^*$

Option D: Content free, push $w$ on stack then push $x$ on stack match $x$ with $x^R$ and then $w$ with $w^R$
Answer:

Related questions

26 votes
26 votes
5 answers
1