• edited by
18,448 views

2 Answers

Best answer
74 74 votes
Correct Answer: $D.$ All are context free.
$L1 \rightarrow$ Push $0$ on stack and when $1$ comes, start popping. If stack becomes empty and $1$'s are remaining start pushing $1$. At end of string accept if stack is non- empty.

$L2 \rightarrow$ Do the same as for $L1$, but accept if stack is empty at end of string.

$L3 \rightarrow$ Do, the same as for $L2$, but for each $1$, pop two $0$'s from the stack and don't do a push for the first $0$.

$L4 \rightarrow$ Do the same as for $L1$, but for each $1$, pop two $0$'s from the stack

All are in fact DCFL. Popping two $0$'s on stack might sound non-trivial but we can do this by popping one symbol and going to a new state. Then on this new state on empty symbol, pop one more symbol from the stack and come back to the original state.
• edited by
7 7 votes

The correct answer is D. All are context free.

A language is context-free if it can be recognized by a non-deterministic pushdown automaton (PDA). A PDA uses a stack to "count" or "match" symbols.

Here is the analysis for each language:

  • $L2 = \{0^i 1^j \mid i = j\}$: This is the classic example of a context-free language. A PDA can push a symbol onto the stack for every 0 it reads, and then pop one symbol for every 1 it reads. If the stack is empty when the input ends, it accepts.

  • $L3 = \{0^i 1^j \mid i = 2j + 1\}$: This is also context-free and even deterministic. A PDA can push all 0s onto the stack. Then, for every 1 it reads, it pops two 0s from the stack. If the input ends and there is exactly one 0 left on the stack, it accepts.

  • $L1 = \{0^i 1^j \mid i \ne j\}$: This language is context-free. It is the union of two separate context-free languages:

    1. $i > j$: A non-deterministic PDA can push all 0s, pop one 0 for each 1, and accept if the input ends while the stack is not empty.

    2. $i < j$: A non-deterministic PDA can push all 0s, pop one 0 for each 1, and accept if the stack becomes empty before the input 1s have finished.

      Since $L1$ is the union of these two CFLs, it is also a CFL.

  • $L4 = \{0^i 1^j \mid i \ne 2j\}$: This language is also context-free for the same reason as $L1$. It is the union of two CFLs:

    1. $i > 2j$: A PDA pushes all 0s, pops two 0s for each 1, and accepts if the input ends while the stack is not empty.

    2. $i < 2j$: A PDA pushes all 0s, pops two 0s for each 1, and accepts if the stack becomes empty before the input 1s have finished.

      This language is also context-free.

Since $L1$, $L2$, $L3$, and $L4$ are all context-free, the correct statement is D.

Answer:
Position:
Show:

Related questions

90 90 votes
10 answers 10 answers
39.8k
39.8k views
go_editor asked Sep 30, 2014
39,807 views
Let $w$ be any string of length $n$ in $\{0,1\}^*$. Let $L$ be the set of all substrings of $w$. What is the minimum number of states in non-deterministic finite automati...
93 93 votes
12 answers 12 answers
39.7k
39.7k views
go_editor asked Sep 30, 2014
39,684 views
Let $L=\{ w \in \:(0+1)^* \mid w\text{ has even number of }1s \}$. i.e., $L$ is the set of all the bit strings with even numbers of $1$s. Which one of the regular express...
73 73 votes
3 answers 3 answers
26.5k
26.5k views
go_editor asked Sep 29, 2014
26,468 views
Let $L_1$ be the recursive language. Let $L_2$ and $L_3$ be languages that are recursively enumerable but not recursive. Which of the following statements is not necessar...
80 80 votes
13 answers 13 answers
37.5k
37.5k views
gatecse asked Feb 14, 2018
37,479 views
Consider the following languages:$\{a^mb^nc^pd^q \mid m+p=n+q, \text{ where } m, n, p, q \geq 0 \}$$\{a^mb^nc^pd^q \mid m=n \text{ and }p=q, \text{ where } m, n, p, q \ge...