Construct Pushdown automata for L = {0(n+m)1m2n | m, n ≥ 0}

Prerequisite – Pushdown automata

Problem: Construct Pushdown automata for L = {0(n+m)1m2n | m, n ≥ 0}

Similar PDA’s-

  • This PDA seems to be similar to PDA of S2 = {0m1(n+m)2n} but the production is different. S2 will produce output which have no of 1’s equal to the sum of no of 0’s and 2’s, while S1 does not.
  • This PDA seems to be similar to PDA of language L2 = {amb(n+m)cn | m,n > 1} but L2 does not contain any production of length 0, 1, 2, 3. While this PDA will accept the empty string, string of length 1, 2, 3 in addition to string accepted by the PDA of language L2.

Example-

Input: NULL String
Output: Accepted

Input: 0000011122
Output: Accepted

Input: 00000112222
Output: Not Accepted  

Approach used in this PDA –
There can be four cases while processing the given input string.



Case 1- m=0:
In this cases the input string will be of the form {0n2n}. In this condition, keep on pushing 0’s in the stack until we encounter with 2. On receiving 2 check if top of stack is 0, then pop it from the stack. Keep on popping 0’s until all the 2’s of the string are processed. If we reach to the end of input string and stack becomes empty, then reached to the final state i.e. Accepts the input string else move to dead state.

Case 2- n=0:
In this cases the input string will be of the form {0m1m}. In this condition, keep on pushing 0’s in the stack until we encounter with 1. On receiving 1 check if top of stack is 0, then pop it from the stack. Keep on popping 0’s until all the 1’s of the string are processed. If we reach to the end of input string and stack becomes empty, then reached to the final state i.e. Accepts the input string else move to dead state.

Case 3- m, n>0:
In this cases the input string will be of the form {0(n+m)1m2n}. In this condition, keep on pushing 0’s in the stack until we encounter with 1. On receiving 1 check if top of stack is 0 then pop it from the stack. Keep on popping 0’s until all the 1’s of the input string are processed.After that, On receiving 2 check if top of stack is 0 then pop it from the stack. Keep on popping 0’s until all the 2’s of the input string are processed If we reach to the end of input string and stack becomes empty, then reach to final state i.e. accept the input string else move to dead state.

Case 4- m=0, n=0:
In this case the input string will be empty. Therefore directly jump to final state.

State transition diagram:



My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.