Construct Pushdown automata for L = {0n1m2m3n | m,n ≥ 0}



Prerequisite – Pushdown automata, Pushdown automata acceptance by final state
Pushdown automata (PDA) plays a significant role in compiler design. Therefore there is a need to have a good hands on PDA. Our aim is to construct a PDA for L = {0n1m2m3n | m,n ≥ 0}

Examples –

Input : 00011112222333
Output : Accepted

Input : 0001122233
Output : Not Accepted

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

  • Case-1: m = 0 – In this cases the input string will be of the form {0n3n}. In this condition, keep on pushing 0’s in the stack until we encounter with 3. On receiving 3 check if top of stack is 0, then pop it (0) from the stack. Pop 0’s until all the 3’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-2: n = 0 – In this cases the input string will be of the form {1m2m}. In this condition, keep on pushing 1’s in the stack until we encounter with 2. On receiving 2 check if top of stack is 1, then pop it (1) from the stack. Keep on pop 1’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-3: m, n>0 – In this cases the input string will be of the form {0n1m2m3n}. In this condition, keep on pushing 0’s and 1’s in the stack until we encounter with 2. On receiving 2 check if top of stack is 1, then pop it (1) from the stack. Keep on pop 1’s until all the 2’s of the input string are processed. Then on receiving 3 check if top of stack is 0, then pop it (0) from the stack. Pop 0’s until all the 3’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.

Final Pushdown automata for the given language is:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.