Open In App

Construct a Turing Machine for language L = {0<sup>n</sup>1<sup>n</sup>2<sup>n</sup> | n≥1}

Prerequisite – Turing Machine
The language L = {0n1n2n | 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.

Article Tags :