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
  • 431
  • 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
  • $q0$ is also a final state, apologies, i missed it out while drawing it... – Subhayan Sep 22 '13 at 23:12
  • oh. very clear. you didn't even need to do the actual pda diagram. so bonus points for that. – user678392 Sep 22 '13 at 23:23
  • i have posted the final answer at the link Gilles provided. and i think he's right, you should try to read his desc. and construct your own, and i am sure you can do that :) – Subhayan Sep 22 '13 at 23:48
  • Could you please explain why these steps work? we 'copy' the input tape onto the stack (q1) and leverage non-determinism for the check we keep reading off the stack and uninterestingly read while we keep encountering the same variables (q2) if the tape becomes empty, we just don't accept the language (q3) if we see even one position, where there's a difference, we are happy, and read the rest of the string (q4) and check if |x|=|y| – user678392 Sep 23 '13 at 00:02
  • 1
    @user678392 please see this. I am pretty confident this is correct. Do you want me to cross post the answer here too? – Subhayan Sep 23 '13 at 07:23
  • You are not even answering the same question as the one I'm asking. So how would it help? – user678392 Sep 23 '13 at 15:56
  • sorry, it wasn't of much help to you, unless you have already solved it yourself, please ref. to Rapheal's post there for the second question, and mine or Gilles answer here for your first question :) – Subhayan Sep 26 '13 at 00: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'
  • 43,613
  • 8
  • 118
  • 182
  • how does this translate into a pda? Can you reword your explanation on L_1. Also, how does the pda work if j = 0 or i,j = 0? – user678392 Sep 22 '13 at 23:03
  • @user678392 My intuitive explanation pretty much tells you how to construct a PDA. I've done about 90% of your homework exercise here, you should at least do the final step by yourself. – Gilles 'SO- stop being evil' Sep 22 '13 at 23:11
  • Given that I don't understand the explanation or are confused by it, I would beg to differ. – user678392 Sep 22 '13 at 23:20
  • you do realize that the solution you linked to is horrendous to understand. – user678392 Sep 22 '13 at 23:25
  • @user678392 $L_1$ is an easy exercise, you've had everything handed to you. $L_2$ is a difficult exercise, if you have tried for yourself and don't understand the solution, feel free to ask a new question where you tell us how far you got and where you're stuck. – Gilles 'SO- stop being evil' Sep 22 '13 at 23:28
  • Well, I'm stuck because I don't see how it is an answer. The answer seems to be: hey, here's a grammar that generates what we want. So it's context-free. – user678392 Sep 23 '13 at 16:01
  • @user678392 That's the usual definition of context-free: a language is context-free if there is a context-free grammar that recognizes it. – Gilles 'SO- stop being evil' Sep 23 '13 at 18:04
  • Fair enough. I want to be able to see why the grammar is the way it is. – user678392 Sep 23 '13 at 20:56
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,450
  • 10
  • 12