Question

In a recent test , I was asked to recognize if the below language is context free:

enter image description here

According to me, it is context free, and can be accepted by the below context free grammar, where S is the start symbol and Y is a non-terminal:

enter image description here

However, my answer was considered to be wrong and so apparently this language is not context free.

I'm confident about my answer, but the response has got me confused. Is my understanding correct? Please let me know if I've missed something.

Was it helpful?

Solution

The language is NOT context free language! your grammar is wrong!

According to language description 0s at suffix should be less then number of 1s and prefix 0s. But using your grammar you can generate wrong string as follows:

Step1: Always replace S by S0
Step2: Now replace S to Y

S --> S0 --> S00 --> S000 --> Y000 

Now you can replace Y to ^ (nul) it gives 000, this string is not in your language.

either replace Y to 0Y1 then Y to ^:

  Y000 --->  0Y1000  ---> 01000

01000 string is not in language. So your grammar does not generate the same language.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top