0

Find a CFG for the following language:

$$L = \{a^i b^j a^n b^m \mid i + j = n + m\}$$

I'm not sure how I can do that context free. I know that I have to borrow one char from the left group for each char from the right group. but not sure how.

Raphael
  • 73,212
  • 30
  • 182
  • 400

1 Answers1

2

The idea is to use non-terminals $X_{\alpha\beta}$, where $\alpha,\beta \in \{a,b\}$, that support the production $X_{\alpha\beta} \to \alpha X_{\alpha\beta} \beta$. You have to combine them somehow so that you obtain the language $L$, but I'll leave the details to you.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514