Prerequisite – Turing Machine

The language L = {0^{n}1^{n}2^{n} | n≥1} represents a kind of language where we use only 3 character, i.e., 0, 1 and 2. In the beginning language has some number of 0’s followed by equal number of 1’s and then followed by equal number of 2’s. Any such string which falls in this category will be accepted by this language. The beginning and end of string is marked by $ sign.

**Examples –**

Input : 0 0 1 1 2 2 Output : Accepted Input : 0 0 0 1 1 1 2 2 2 2 Output : Not accepted

**Assumption:** We will replace 0 by X, 1 by Y and 2 by Z

**Approach used –**

First replace a 0 from front by X, then keep moving right till you find a 1 and replace this 1 by Y. Again, keep moving right till you find a 2, replace it by Z and move left. Now keep moving left till you find a X. When you find it, move a right, then follow the same procedure as above.

A condition comes when you find a X immediately followed by a Y. At this point we keep moving right and keep on checking that all 1’s and 2’s have been converted to Y and Z. If not then string is not accepted. If we reach $ then string is accepted.

**Step-1:**

Replace 0 by X and move right, Go to state Q1.**Step-2:**

Replace 0 by 0 and move right, Remain on same state

Replace Y by Y and move right, Remain on same state

Replace 1 by Y and move right, go to state Q2.**Step-3:**

Replace 1 by 1 and move right, Remain on same state

Replace Z by Z and move right, Remain on same state

Replace 2 by Z and move right, go to state Q3.**Step-4:**

Replace 1 by 1 and move left, Remain on same state

Replace 0 by 0 and move left, Remain on same state

Replace Z by Z and move left, Remain on same state

Replace Y by Y and move left, Remain on same state

Replace X by X and move right, go to state Q0.**Step-5:**

If symbol is Y replace it by Y and move right and Go to state Q4

Else go to step 1**Step-6:**

Replace Z by Z and move right, Remain on same state

Replace Y by Y and move right, Remain on same state

If symbol is $ replace it by $ and move left, STRING IS ACCEPTED, GO TO FINAL STATE Q5

## Recommended Posts:

- Construct a Turing Machine for language L = {ww | w ∈ {0,1}}
- Construct a Turing Machine for language L = {ww
^{r}| w ∈ {0, 1}} - Construct a Turing machine for L = {a
^{i}b^{j}c^{k}| i*j = k; i, j, k ≥ 1} - Construct Turing machine for L = {a
^{n}b^{m}a^{(n+m)}| n,m≥1} - Turing Machine
- Turing machine for multiplication
- Turing Machine for subtraction | Set 2
- Turing machine for subtraction | Set 1
- Turing Machine for addition
- Turing machine for copying data
- Difference between Mealy machine and Moore machine
- Computer Organization | Machine Control Instruction
- 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^{m}3^{n}| m,n ≥ 0} - Construct Pushdown automata for L = {0
^{n}1^{m}2^{(n+m)}| m,n ≥ 0}

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.