• retagged by
20,096 views
53 53 votes

Which one of the following languages over $\Sigma=\{a, b\}$ is NOT context-free?

  1. $\{ww^R \mid w \in \{a, b\}^*\}$
  2. $\{wa^nb^nw^R \mid w \in \{a,b\}^*, n \geq 0\}$
  3. $\{wa^nw^Rb^n \mid w \in \{a,b\}^* , n \geq 0\}$
  4. $\{ a^nb^i \mid i \in \{n, 3n, 5n\}, n \geq 0\}$

3 Answers

Best answer
109 109 votes

Answer : C

Detailed Video Solution with Complete Analysis & Variations: https://www.youtube.com/watch?v=ZSGsmg_9X4o&t=5744s


Input alphabet $\Sigma = \{ a,b\}$


A.

$\{ww^R| w \in \{ a,b\}^*\}$ 

This language is well-known CFL. The CFG generating this language is as following :

$G_1 : S \rightarrow aSa|bSb| \in$


B. 

$\{wa^nb^nw^R| w \in \{ a,b\}^*, n\geq 0\}$ 

This language is also CFL and can easily be generated by a slight modification in the above Grammar $G_1$. The CFG generating this language is as following :

$G_2 : S \rightarrow aSa|bSb| \in | A$

$\,\,\,\,\,\,\,\,\,\,\,A \rightarrow aAb | \in$


D.

$\{a^nb^i| i \in \{ n,3n,5n\}^, n\geq 0\}$ 

This language is also CFL. It can be seen as Union of Three CFLs $a^nb^n,a^nb^{3n}, a^nb^{5n}.$. The CFG generating this language is as following :

$G : S \rightarrow A|B|C $

$\,\,\,\,\,\,\,\,\,\,\,A \rightarrow aAb | \in$

$\,\,\,\,\,\,\,\,\,\,\,B \rightarrow aBbbb | \in$

$\,\,\,\,\,\,\,\,\,\,\,C \rightarrow aCbbbbb | \in$


So, By now, you could get the answer to be the Third Option i.e. $C$ Or we can use Pumping lemma to show that It is Non-CFL.


C.

$L = \{wa^nw^Rb^n| w \in \{ a,b\}^*, n\geq 0\}$ 

$L$ is a Non-CFL.

We can use "Pumping lemma for CFL" to prove that $L$ is Not a CFL.

Pumping lemma for CFLs:

Let $L$ be a CFL. Then there exists some integer constant $P \geq 1$ (Called Pumping length or pumping-lemma constant)  such that if $w ∈ L$ with $|w| ≥ P,$ then we can write $w = uvxyz,$ subject to the following conditions:

1. $|vxy| ≤ P.$

2. $vy \neq \in .$

3. For all $i ≥ 0,$ we have $uv^ixy^iz ∈ L.$

i.e. Informally, For every sufficiently large string $w$ in $L,$ We must be able to split it such that it is possible to find at most two short, nearby substrings that we can “pump” $i$ times in tandem, for any non-negative integer $i,$ and the resulting string will still be in that language.  

Now, Assume that Given $L$ is CFL, Hence, It will satisfy Pumping lemma for CFL.

So, There must be some integer constant (pumping length) $\geq1$ exists for this language. Let it be $P.$

So, Now for every string $w \in L$ whose length is greater than or equal to $P,$ we must have some partition $uvxyz$ satisfying all the above conditions.

So, Let me take the string $b^{2P} a^{2P}b^{2P}b^{2P}$, Now Try to split it into five parts $uvxyz$ such that All the Three conditions of pumping lemma must satisfy.

Basically in Pumping lemma for CFL, You want to find $"$at most $P"$ consecutive symbols in the String(anywhere in the String) such that you can find two short sub-strings in that part and Pump those sub-strings in tandem. 

But for the above String  $b^{2P} a^{2P}b^{2P}b^{2P}$, we cannot find any such at most $P$ consecutive symbols anywhere in the string which will satisfy the Pumping lemma conditions. (Hint : Take Those at most $P$ consecutive symbols in the first part of the string i.e. $b^{2P}$ or in the second part i.e. $a^{2P} $ or in third part or in fourth part or between the parts etc.. covering all possible partitions..  )

So, Given language doesn't satisfy Pumping lemma and hence, $L$ is Not CFL.


The informal/intuitive idea for Non-CFLness of $L$ (language in Option $C$) is that You need PDA to do the reverse matching i.e. $w \,\,\,matched\,\,\,with\,\,\,w^R$ But Because $a^n$ is in between $w\,\,and\,\,w^R$ and $b^n$ is after $w^R$, You can either match $ww^R$ or you can match $a^nb^n$ but Not both simultaneously.  This is Informal Idea and by practice It becomes easier to check for a language being CFL or Not using this informal method.

Detailed Video Solution with Complete Analysis & Variations: https://www.youtube.com/watch?v=ZSGsmg_9X4o&t=5744s

• edited by
38 38 votes
$\{ww^r \} \rightarrow$ well known CFL.

$\{ wa^n b^n w^r \} \rightarrow$ inside out comparison. PDA can do this.

$\{ a^n b^i, \: i=n, \: 3n,\: 5n\} \rightarrow$ is CFL

$\{wa^n w^r b^n \} \rightarrow$ Alternate comparison. PDA can not do this.
• edited by
3 3 votes
I have a super easy trick.

For checking the given grammar is context free grammar or not we have to go to the stack if the stack is accept the language or not by empty stack.

If able to make the stack empty or able to make accepted string then you can say that a given grammar if context to grammar otherwise it is not

A) WW^R  every symbol is for because both lengths are equal = CFG

B) Wa^nb^nW^R Push W Push a pop b pop W (n = same length) = CFG

C) Wa^nW^Rb^n Push W Push a then how can we pop W because W in in between. = Not CFG

D) a^nb^i Here lengths are equal then we can easily push and pop. = CFG

 

 
Answer:
Position:
Show:

Related questions

49 49 votes
4 answers 4 answers
23.8k
23.8k views
Arjun asked Feb 7, 2019
23,804 views
Consider the following sets:S1: Set of all recursively enumerable languages over the alphabet $\{0, 1\}$S2: Set of all syntactically valid C programsS3: Set of all langua...
115 115 votes
13 answers 13 answers
36.7k
36.7k views
Arjun asked Feb 7, 2019
36,714 views
Let $\Sigma$ be the set of all bijections from $\{1, \dots , 5\}$ to $\{1, \dots , 5 \}$, where $id$ denotes the identity function, i.e. $id(j)=j, \forall j$. Let $\circ$...
57 57 votes
5 answers 5 answers
24.1k
24.1k views
Arjun asked Feb 7, 2019
24,143 views
If $L$ is a regular language over $\Sigma = \{a,b\} $, which one of the following languages is NOT regular?$L.L^R = \{xy \mid x \in L , y^R \in L\}$$\{ww^R \mid w \in L \...
82 82 votes
7 answers 7 answers
56.4k
56.4k views
Arjun asked Feb 7, 2019
56,373 views
For $\Sigma = \{a ,b \}$, let us consider the regular language $L=\{x \mid x = a^{2+3k} \text{ or } x=b^{10+12k}, k \geq 0\}$. Which one of the following can be a pumping...