I have come across two completely different answers.
One says that:
Yes, there does exist a context-free grammar for {0i1j | 1≤i≤j≤2i}
, the following grammar ensures that there can be half or lesser 0’s for the 1’s that are present:
S -> 0S11 | 0S1 | 01
The other: No, proof by contradiction:
Case 1:
Suppose you push i 0s onto the stack.
Pop off j 1s.
You can’t determine if j<=2i.
Case 2:
Suppose you push 2i 0s onto the stack.
Pop off j 1s.
You can’t determine if j>=i.
Any other value pushed on the stack not equal to i or 2i is a value relative to either of these two values, so the same reasoning applies.
Are either correct? Thanks so much!