edited by
21,225 views
50 votes
50 votes

Consider the following languages:

  1. $\{a^mb^nc^pd^q \mid m+p=n+q, \text{ where } m, n, p, q \geq 0 \}$
  2. $\{a^mb^nc^pd^q \mid m=n \text{ and }p=q, \text{ where } m, n, p, q \geq 0 \}$
  3. $\{a^mb^nc^pd^q \mid m=n =p \text{ and } p \neq q, \text{ where } m, n, p, q \geq 0 \}$
  4. $\{a^mb^nc^pd^q \mid mn =p+q, \text{ where } m, n, p, q \geq 0 \}$

Which of the above languages are context-free?

  1. I and IV only
  2. I and II only
  3. II and III only
  4. II and IV only
edited by

9 Answers

5 votes
5 votes

Many might have marked B,but one must be able to rigorously prove it:

Why is 4 false?

Here we must know what m is.Multiplication can only be performed if we know one of its operands.There is no bound on m, and since you cannot count till infinity(counting requires a distinct state for each increment) and you cannot have infinite states counting is not possible.This can be done with the help of LBA

Why is 2 true?

We'll decompose the problem into 2 parts as we don't have to be deterministic.

Case 1:

m-n = p-q .Do,simple push and pop for 'a' and 'b' respectively.Now,if 'b' is one the stack terminate . else do the similar operation for 'c' and 'd' .Now compare the leftover 'a' with leftover 'c',this is again trivial.

Case 2: n-m = p-q can be done similarly.

Answer:b)

edited by
3 votes
3 votes

II is obviously CFL

for option IV as multiplication symbol is not given there we can consider it as concatenation

lets take example

a^30 b^5 c^200 d^105
now here m=30 n=5 p=200 q=105

mn=p+q is   305=305

now we can design pda as following

1)push 10 'a' for Each input 'a' in stack

2)push all b's in stack

now stack contains 305 a's and b's for above example

3)match all a and b in stack with input c and d

4)if stack is empty and input is null then accept otherwise reject

Hence OPTION D

1 votes
1 votes
I don't think the options are correct(The numbering is wrong). But I can definitely say that I and II, both are CFL as you easily construct PDAs for them. You can easily count the m's, n's & p's, q's in them and them push/pop accordingly.

III is definitely not a CFL. You cannot construct a PDA for it as you have to ensure that m = n = p, that means counting 3 of them and it is also given that p does not equal q, so q can be anything.

So I hope you can figure out the answer(The options are incorrect I think. So, check out!) :)
Answer:

Related questions

41 votes
41 votes
1 answer
3