• edited by
23,672 views
59 59 votes

Which of the following languages are context-free?

$L_1: \left\{a^mb^na^nb^m \mid m, n \geq 1\right\}$

$L_2: \left\{a^mb^na^mb^n \mid m, n \geq 1\right\}$

$L_3: \left\{a^mb^n \mid m = 2n +1 \right\}$

  1. $L_1$ and $L_2$ only
  2. $L_1$ and $L_3$ only
  3. $L_2$ and $L_3$ only
  4. $L_3$ only

3 Answers

Best answer
81 81 votes

first check for $L_1$. now look $a^m$ & $b^m$ and $a^n$ & $b^n$ must $be$ comparable using one stack for CFL.
now take a stack push all $a^m$ in to the stack  then push all $b^n$ in to stack now $a^n$ is coming so pop $b^n$ for each $a^n$ by this $b^n$ and $a^n$ will b comparable. now we have left only $a^m$ in stack and $b^m$ is coming so pop $a^m$ for each $b^m$ by which we can compare $a^m$ to $b^m$ ..we conclude that we are comparing this $L_1$ using a single stack so this is CFG.

now for $L_2$.this can not be done in to a single stack because $m$ and $n$ are not comparable we can not find when to push or  pop so this is CSL.

now for $L_3$.push all $a$'s into stack and pop $2a$ 's for every $b$  and at last we left with a single $a$ .
bcz here $aaaaabb$ is a valid string where $m=2n+1$ and $n=2$. So realized using single stack hence $L_3$ is CFG.

so the option is B.. $L_1$ and $L_3$ are CFG

• edited by
6 6 votes

L1: First push all the a's in the stack then push all the b's in the stack. Now pop all the b's from the stack watching next no. of a's. And then pop all the a's from the stack watching next no. of b's. So can be done by PDA, hence CFL.

L2: First push all the a's in the stack then push all the b's in the stack. Now again a's come which cannot be compared by previous a's in the stack because at top of the stack's there are b's which is also needed to be pushed for further comparision with the next b's. So not CFL.

L3: First simply read one 'a', then push one 'a' in the stack after reading two a's and then pop all the a's by reading the b's. Since can be done by PDA hence CFL.
Option B

Answer:
Position:
Show:

Related questions

49 49 votes
4 answers 4 answers
13.9k
13.9k views
go_editor asked Feb 16, 2015
13,862 views
Language $L_1$ is polynomial time reducible to language $L_2$. Language $L_3$ is polynomial time reducible to language $L_2$, which in turn polynomial time reducible to l...
67 67 votes
8 answers 8 answers
28.9k
28.9k views
go_editor asked Feb 14, 2015
28,918 views
Let $L$ be the language represented by the regular expression $\Sigma^*0011\Sigma^*$ where $\Sigma = \{0, 1\}$. What is the minimum number of states in a DFA that recogni...
8 8 votes
4 answers 4 answers
8.5k
8.5k views
go_editor asked Feb 16, 2015
8,468 views
Consider the following software items: Program-$X$, Control Flow Diagram of Program-$Y$ and Control Flow Diagram of Program-$Z$ as shown belowThe values of McCabe's Cyclo...
69 69 votes
5 answers 5 answers
21.1k
21.1k views
go_editor asked Feb 16, 2015
21,120 views
Consider the following C program:#include<stdio.h int f1(void); int f2(void); int f3(void); int x=10; int main() { int x=1; x += f1() + f2 () + f3() + f2(); printf("%d", ...