1

(1) $L_1 = \{a^ib^{i+j}c^j|i,j\geq 0\} $

(2) $L_2 = \{xy | x,y \in \{0,1\}^*, x \neq y, |x| = |y| \}$

I doubt that $L_1$ is CFL. I've been trying to go with the string $s$ = $a^pb^{2p}c^p$. Thus, we can write $s$ as $uvxyz$. Now I'm trying to show $uv^2xy^2z$ is not in $L_1$.

I really have no idea how to approach (2). And if it is context free, how in the world would you draw a pda?

user678392
  • 441
  • 2
  • 5
  • 12

3 Answers3

3

For the first one, $$L_1 = \{a^i,b^{i+j}c^j \mid i,j \geq 0 \} $$

Here's an rough idea of the algorithm:

  • read off the all '$a$'s and push $a$ into the stack
  • upon seeing a '$b$', pop the '$a$'s till the stack is empty
  • then again as long as reading '$b$'s keep pushing $b$ into the stack
  • on seeing a $c$, start popping the stack until empty.

enter image description here

For the second one,

Please see my answer here, The other answer is equally good (perhaps even better and simpler) than mine.

Subhayan
  • 1,696
  • 10
  • 19
1

$L_1$ is context-free. It is fairly easy to write a grammar for it: $$ \begin{align} S &\to A C \\ A &\to \epsilon \\ A &\to a A b \\ C &\to \epsilon \\ C &\to b C c \\ \end{align} $$

Intuitively, $L_1$ needs to remember the number of $a$'s, then when a matching number of $b$'s have been found it needs to remember the excess, and compensate by $c$'s. This is within the capabilities of a pushdown automaton (push a token per excess $a$, pop one when a $b$ comes, then start pushing $b$'s when the stack is empty and pop them when $c$'s come).

$L_2$ is also context-free, but this is more difficult to see. Try reasoning by induction and deducing a grammar, but be warned that it isn't straightforward. Start with the idea that either $x$ and $y$ start with the same letter, in which case the rest of the words must be different, or $x$ and $y$ start with the same letter, in which case the rest of the words can be arbitrary. This is not enough, because you can't keep track of the fact that you're decomposing into words of equal length. So you need to do more to ensure that you aren't including words of the form $x x$ that you happened to break down in the wrong place. See Show that { xy ∣ |x| = |y|, x ≠ y } is context-free for a solution.

Gilles 'SO- stop being evil'
  • 44,159
  • 8
  • 120
  • 184
0

Another simple way to see that (1) is a context-free is to observe that both $L'_1=\{a^ib^i\mid i\ge 0\}$ and $L''_1 = \{b^jc^j \mid j\ge 0\}$ are context-free, and $L_1$ is simply $L'_1\cdot L''_1$, the concatenation of $L'_1$ and $L''_1$. And we know that the set of context-free languages is closed under concatenation.

Dai
  • 1,460
  • 10
  • 12