Build Turing Machine

112 Views Asked by At

My question is how to build a Turing machine that is able to replace ab's in pairs with X, hence X will reflect the number of pairs.

1

There are 1 best solutions below

15
On BEST ANSWER

First of all, no, the Turing-machine does not read or write symbols in pairs; it reads and writes exactly one symbol at a time.

Second, note that the strings to be accepted merely need to have as many $a$'s and $b$'s: the strings do not have to be of the form $(ab)^*$, but you should also accept a string like $aaabbb$ or $babbbaaa$. So when it says 'pairs' it does not mean that you have succesive $ab$'s on the input.

The general strategy is given in the hint in the question: for every $a$ that you find, also find a $b$, and replace both of them with $X$ ... and then keep repeating that.

The basic 'fork' or 'split' that you see, i.e the fact that from the starting node there are two possible nodes that you can transition to, reflects of course the fact that you can first run into an $a$, and thus will have to look for a $b$ later on the tape, or that you can first run into a $b$, and thus will look for an $a$ later.

So try that!