Prerequisite – Pushdown automata, NPDA for accepting the language L = {a^{m}b^{(n+m)}c^{m} | m, n >= 1}

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

**Example:**

Input:011122Output:AcceptedInput:00000112222Output: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 {1^{n}2^{n}}. 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 from the stack. Keep on popping 1’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 {0^{m}1^{m}}. 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^{m}1^{(m+n)}2^{n}}. 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 0’s are popped and stack became empty.After that, 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 from the stack. Keep on popping 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 4- m=0, n=0:**

In this case the input string will be empty. Therefore directly jump to final state.

**State transition diagram: **

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- Difference between Pushdown Automata and Finite Automata
- Construct Pushdown Automata for given languages
- Construct Pushdown Automata for all length palindrome
- Construct Pushdown automata for L = {0
^{n}1^{m}2^{m}3^{n}| m,n ≥ 0} - Construct Pushdown automata for L = {a
^{(2*m)}c^{(4*n)}d^{n}b^{m}| m,n ≥ 0} - Construct Pushdown automata for L = {0
^{n}1^{m}2^{(n+m)}| m,n ≥ 0} - Construct Pushdown automata for L = {0
^{(n+m)}1^{m}2^{n}| m, n ≥ 0} - Introduction of Pushdown Automata
- Pushdown Automata Acceptance by Final State
- Detailed Study of PushDown Automata
- Automata Theory | Set 1
- Automata Theory | Set 2
- Automata Theory | Set 3
- Automata Theory | Set 4
- Automata Theory | Set 5
- Introduction of Finite Automata
- Designing Finite Automata from Regular Expression (Set 1)
- Generating regular expression from Finite Automata
- Designing Non-Deterministic Finite Automata (Set 3)
- Practice problems on finite automata

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.