Prerequisite – Turing Machine
We have to design a Turing machine for a^i b^j where i<j and i>0.
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.
Input: aabbbb Output: Accepted Input: aaabb Output: Not Accepted
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.