Prerequisite – Turing Machine
Task :
We have to design a Turing machine for a^i b^j where i<j and i>0.
Analysis :
Here the main thing to notice that i<j. It means that the count of ‘b’ in the string is always greater than the count of ‘a’. Therefore we can write a^i b^j like that –
a^i b^j = a^n b^n + extra number of b.
Examples –
Input: aabbbb Output: Accepted Input: aaabb Output: Not Accepted
Approach :
Let us understand the approach by taking a string “aabbb”.
- Scan the input from the left.
- First, replace an ‘a’ with ‘X’ and move 1 step right. Then skip all the a’s and b’s and move right.
- When the pointer reaches Blank(B) it scans the input from the right and replaces the first ‘b’ with ‘Y’.
- Again the pointer reaches Blank(B). It now scans the input from left to right. The pointer moves forward and replaces ‘a’ with ‘X’.
- Again the pointer reaches Blank(B). It now scans the input from the right to left. The pointer moves forward and replaces ‘b’ with ‘y’.
- We repeat the same steps until we convert all the a’s to ‘X’. b’s equal to the count of a’s will also convert to ‘Y’ and we will be left with some of the remaining b’s.

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:
- Construct Turing machine for L = {an bm a(n+m) | n,m≥1}
- Construct a Turing Machine for language L = {0n1n2n | n≥1}
- Construct a Turing Machine for language L = {wwr | w ∈ {0, 1}}
- Construct a Turing Machine for language L = {ww | w ∈ {0,1}}
- Construct a Turing machine for L = {aibjck | i>j>k; k ≥ 1}
- Construct a Turing machine for L = {aibjck | i*j = k; i, j, k ≥ 1}
- Construct a Turing machine for L = {aibjck | i< j< k; i ≥ 1}
- Construct a Turing machine for L = {aibjck | i < j < k or i > j > k}
- Construct a Turing Machine for a language L = {aibjck | i<j<k or i>j>k} ∩ {aibjck | i>j>k or i>j>k}
- Construct a Turing Machine for language L = {02n1n | n>=0}
- Construct a Turing Machine for language L = {a^n b^m c^nm where n >=0 and m >= 0}
- Construct Turing Machine for incrementing Binary Number by 1
- Turing Machine for subtraction | Set 2
- Turing Machine for addition
- Turing machine for multiplication
- Turing machine for subtraction | Set 1
- Turing machine for copying data
- Turing machine for 1's and 2’s complement
- Turing Machine as Comparator
- Modifications to standard Turing Machine
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.



