4

I was trying to find the CFG for the language below. However, I couldn't do that. Can anyone help with this problem?

$$\{1^n 0^m 1^k 0^p | n \geq 2, m,k,p \geq 1, n+k = m+p\}$$

Astyx
  • 3,930

1 Answers1

1

Assume $m\ge k$. Then $$1^n0^m1^k0^p= 1^n0^{m-k} 0^k1^k0^{n+k-m} = 1^{n+k-m}\underbrace{1^{m-k}0^{m-k}}_{V \text{ if } m-k\ge 1} \underbrace{(0^k1^k)}_{U}0^{n+k-m}\,.$$

Such words are generated by $$\begin{align}U&\to 0U1|01\\ V&\to 1V0|10\\ T&\to 1VU0|1T0|11U00\end{align}\,.$$

Find a context free grammar for the case $m\lt k$ and you should be good to go.

Astyx
  • 3,930