# NPDA for L = {0^{i}1^{j}2^{k} | i==j or j==k ; i , j , k >= 1}

Prerequisite – Pushdown automata, Pushdown automata acceptance by final state

The language L = {0^{i}1^{j}2^{k} | i==j or j==k ; i , j , k >= 1} tells that every string of ‘0’, ‘1’ and ‘2’ have certain number of 0’s, then certain number of 1’s and then certain number of 2’s. The condition is that count of each of these 3 symbols should be atleast 1. Two important conditions for this language are that either count of 0 should be equal to count of 1 OR count of 1 should be equal to count of 2. Assume that string is ending with ‘$’.

**Examples:**

Input: 0 0 0 1 1 1 2 2 2 2 2 Here 0's = 3, 1's = 3 so i = j, 2's = 5 Output: Accepted Input: 0 0 1 1 1 2 2 2 Here 0's = 2, 1's = 3, 2's = 3 so j = k Output: Accepted Input : 0 0 1 1 1 2 2 2 2 Here 0's = 2, 1's = 3, 2's = 4 Output: Not accepted

There are 2 approaches for the solution. First is for i==j and second is for j==k. These are:

**Steps for i == j :**

- Input all 0’s in the stack
- When we get 1 as input pop a 0 from stack and goto next state.
- If input is 1 then pop 0 from stack.
- If stack becomes empty (i.e., every 0 corresponding to a 1 has been popped so i = j) and input is 2 then ignore it and goto next state.
- If input is 2 then ignore it . If input is finished and $ is received then goto final state.

**Steps for j == k :**

- Input all 0’s in the stack
- When we get 1 as input push it onto stack and goto next state.
- If input is 1 then push it onto stack.
- If input is 2 pop a 1 from stack and goto next state.
- If input is 2 then pop 1 from stack. If input is finished and $ is received then pop a 0 from stack.
- Pop all remaining 0’s from the stack. If stack becomes empty then goto final state .

## Recommended Posts:

- NPDA for accepting the language L = {a
^{n}b^{(2n)}| n>=1} U {a^{n}b^{n}| n>=1} - NPDA for accepting the language L = {a
^{i}b^{j}c^{k}d^{l}| i==k or j==l,i>=1,j>=1} - NPDA for accepting the language L = {a
^{m}b^{(2m+1)}| m ≥ 1} - NPDA for accepting the language L = {a
^{m}b^{n}c^{n}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{(m+n)}b^{m}c^{n}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{n}b^{m}| n,m ≥ 1 and n ≠ m} - NPDA for accepting the language L = {a
^{n}b^{n}c^{m}| m,n>=1} - NPDA for accepting the language L = {a
^{m}b^{n}c^{(m+n)}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{2m}b^{3m}| m ≥ 1} - NPDA for accepting the language L = {a
^{n}b^{n}| n>=1} - NPDA for accepting the language L = {a
^{m}b^{(m+n)}c^{n}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{m}b^{n}c^{p}d^{q}| m+n=p+q ; m,n,p,q>=1} - NPDA for accepting the language L = {a
^{m}b^{(2m)}| m>=1} - NPDA for accepting the language L = {a
^{n}b^{m}c^{n}| m,n>=1} - NPDA for the language L ={w∈ {a,b}*| w contains equal no. of a's and b's}

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.