209 views

Let $L=\{w \mid w \in (0+1)^+ , N_0(w) \le N_1(w) \le 2N_0(w) \}$,where $N_i(w)$ represents number of $i's$ in string $w$.

a) Give a CFG for $L$

b) is Lc =  Σ*- L context - free?

c) Let $\frac{1}{2}$L = $\{x | ∃y ∈ L , |x| = |y| , x.y ∈ L \}$.is $\frac{1}{2}$L context-free?

edited | 209 views
0
No it will be context-free
+2

L can be written as L= {w | w ∈ (0+1)+ , N1(w) =N0(w) } U {w | w ∈ (0+1)+ , N1(w) =N0(w)+1 } U {w | w ∈ (0+1)+ , N1(w) =N0(w)+2} U..........U {w | w ∈ (0+1)+ , N1(w) =2N0(w) } .Each of them individually itself context-free.So union is context-free.

0
Why can't we apply this union approach to $a^{n}b^{n}c^{n}$ to make it CFL?!
0

Akhilesh Singla  how would you do union for this language?

0
@Sambit I think you are taking union on infinitely many context free languages so the result may not be context free.

By the way can u please tell me the source of the problem.

+1 vote

a) $w$ will be CFL. Now how it will be CFL? Say grammar starts with 1.

So, first push 1,

Now, when 0 comes pop 1 with 0

if some extra 0 come push them in stack

then again when 1 comes pop 0 with 1

and like that we need to proceed, until it is empty stack.

[We can think grammar like this

$S\rightarrow 0S1|0S11|1S0|11S0|10S1|1S01|1|01|011|10|110|101$, but it is not a fully correct grammar]

It cannot be represented with a grammar

b)Complement of L will be $\left \{w|w\epsilon \left(0+1 \right ) ^{*}\right \}$ where $N_{0}\left ( w \right )>N_{1}\left ( w \right )$ or $N_{1}\left ( w \right )>2N_{0}\left ( w \right )$

c)yes it will be CFG.

Say grammar is $L=0^{n}1^{n}$

then $\frac{1}{2}L$ will be subset of $0^{n}1^{n}$. Now subset of CFG will be CFG or regular.

For example $L=0^{n}1^{n}$

and $1/2L=0^{n}$ which will be $0^{*}$ or $0^{*}1^{*}$

or it could be $0^{n/2}1^{n/2}$ , which is CFL

So, will be Regular or CFL

https://gateoverflow.in/93981/half-l

edited by
0
Ankit can u please show that how ur grammar generates the string 01110. I tried it but cant find.

Thanks a lot for ur effort
0
@kushagra ,

S ---> 0A

>  01B1B

> 01(epsilon) 1 B

> 0111B0

> 0111(epsilon)0

> 01110
+1
Oh yes now I get it I think your grammar is correct

Thanks a lot.
0
@ankit

cannot generate 011110
0
yes b) is NCFL

@ankit

Can we generate grammar for $ww^{r}$?
+2
S-> 1S1 | 0S0 | epsilon

grammar for ww^r
0
@srestha , 011110 is not in the language....here, no. of zeros+1 != no. of ones
+1
yes, I got a grammar

$A\rightarrow B|\epsilon$

$B\rightarrow 0A1|1A0|1B1|1C1|0A11|01A1|11A0|1A10|10A1|1A01|1B11|11B1|1D11|11D1|C$

$C\rightarrow 0C0|0B0$

$D\rightarrow 0D00|0B00|00D0|00B0$
0
I came upto this

Still some extra string coming

@ankit

why 011110 not in language? It is in
+1
@srestha , yes , some extra string like 11101 is still coming but nice effort :)...In above , I have not written grammar  for original question ,I have written grammar for language where  no. of zeros+1 = no. of ones in the strings...

+1 vote
1
+1 vote
2
+1 vote