Construct Turing Machine for L = {a^i b^j | i<j, i>0}

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”.



  1. Scan the input from the left.
  2. First, replace an ‘a’ with ‘X’ and move 1 step right. Then skip all the a’s and b’s and move right.
  3. When the pointer reaches Blank(B) it scans the input from the right and replaces the first ‘b’ with ‘Y’.

  4. Again the pointer reaches Blank(B). It now scans the input from left to right. The pointer moves forward and replaces ‘a’ with ‘X’.
  5. 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’.
  6. 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.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.