3

What is the CFG of the complement of L={ww|w belongs to {0,1}*}?

phooji
  • 10,086
  • 2
  • 38
  • 45
Uri
  • 25,622
  • 10
  • 45
  • 72
  • 2
    Call me skeptical, but I have the impression you want us to do your homework for you. Please feel free to remove the tag if it's not the case though. – phooji Mar 28 '11 at 02:54
  • 5
    @phooji: Yes it's homework. I think 5am is a good time to admit failure and seek help. – Uri Mar 28 '11 at 02:56
  • 2
    Start asking such questions on [CSTheory](http://cstheory.stackexchange.com/) – Ravindra S Jul 16 '12 at 19:05
  • 2
    I’m voting to close this question because it is not about programming. It might be a better fit for [cs.se] – Tomerikoo May 02 '21 at 18:22

2 Answers2

11

First of all observe the fact that any odd word is part of the language. Let's define the following languages:

L1={w1w|w{0,1}*}, L0={w0w|w{0,1}*}

These languages can be defined with the following CFG:

S0/1 -> |0S0|1S1|0S1|1S0

Now look at L3:

L3=(L1)U(L2)U(L1L2)U(L2L1)

It is context free from closure to union and concatenation.

Let's prove that L3 is the language we're looking for. First of all as we have seen it deals with all possible odd length words. As for the even length words, if they are in the language, there is one pair of terminals, at least, which is different on both sides of the word. Call this pair a and b. Every even word can be divided like this:

(x_1^m)(a)(x_2^m)(y_1^n)(b)(y_2^n)

and this is exactly

(L1L2)U(L2L1)

This implies that CFG languages are not closed under complement.

Uri
  • 25,622
  • 10
  • 45
  • 72
0

The previously provided answer is incorrect as it doesn't cover all strings present in complement of L for example 011,110,11001, etc. (Previous answer caused me lose some precious marks, so updating :) ) The following grammar can instead be used to prove that L complement is CFL.

S→A|B|AB|BA

A→a|aAa|aAb|bAb|bAa

B→b|aBa|aBb|bBb|bBa

A generates words of odd length with a in the centre. Same for B and b.

More clear explanation is present here.

raaj
  • 1