1
$\begingroup$

(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?

$\endgroup$
1

3 Answers 3

3
$\begingroup$

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.

$\endgroup$
7
  • $\begingroup$ $q0$ is also a final state, apologies, i missed it out while drawing it... $\endgroup$
    – Subhayan
    Commented Sep 22, 2013 at 23:12
  • $\begingroup$ oh. very clear. you didn't even need to do the actual pda diagram. so bonus points for that. $\endgroup$
    – user678392
    Commented Sep 22, 2013 at 23:23
  • $\begingroup$ 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 :) $\endgroup$
    – Subhayan
    Commented Sep 22, 2013 at 23:48
  • $\begingroup$ 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| $\endgroup$
    – user678392
    Commented Sep 23, 2013 at 0:02
  • 1
    $\begingroup$ @user678392 please see this. I am pretty confident this is correct. Do you want me to cross post the answer here too? $\endgroup$
    – Subhayan
    Commented Sep 23, 2013 at 7:23
1
$\begingroup$

$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.

$\endgroup$
8
  • $\begingroup$ 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? $\endgroup$
    – user678392
    Commented Sep 22, 2013 at 23:03
  • $\begingroup$ @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. $\endgroup$ Commented Sep 22, 2013 at 23:11
  • $\begingroup$ Given that I don't understand the explanation or are confused by it, I would beg to differ. $\endgroup$
    – user678392
    Commented Sep 22, 2013 at 23:20
  • $\begingroup$ you do realize that the solution you linked to is horrendous to understand. $\endgroup$
    – user678392
    Commented Sep 22, 2013 at 23:25
  • $\begingroup$ @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. $\endgroup$ Commented Sep 22, 2013 at 23:28
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.