How is $\{uv \in \{0,1\}^* | \space|u|=|v| \text{ and } u\neq v \text{ at exactly 2 characters} \}$ not a CFL?

91 Views Asked by At

I'm looking at the following language, and it is given to me that it is not a CFL: $$\{uv \in \{0,1\}^* | \space|u|=|v| \text{ and } u\neq v \text{ at exactly 2 characters} \}$$

However, if I understand the language correctly, the following CFG should describe the language above:

$$S\rightarrow 0S0|1S1|S_1\\ S_1\rightarrow 0S_21 | 1S_20\\ S_2\rightarrow 0S_31 | 1S_30\\ S_3\rightarrow 0S_30 | 1S_31 | \epsilon$$

I can't figure out what I'm doing wrong, because I cannot see how the language above is not a CFL. Am I reading the language incorrectly?

1

There are 1 best solutions below

1
On

there are couple of problems with your language and the language they give:

first notice that the two characters that are different in the original language can be in any place of u and v, but in your language the different characters comes immedietly one after another, however this can be easily fixed by adding an intermediate variable between S1 and S2 which acts similarily like S , S3

secondly the important part is that what happens in S is not generating the same word from the end but it reverses it, therefor the language you created is: $$u00vv^{R}11u^{R}+u01vv^{R}01u^{R}+u10vv^{R}10u^{R}+u11vv^{R}00u^{R}$$