I try to construct a TM that accepts the language $\{ ww \mid w \in \{a,b\}^* \}$.
Between the words $w$ is no delimeter, so I don't know, how my TM can know where the first $w$ ends and the second $w$ begins.
Is there a trick for this?
I try to construct a TM that accepts the language $\{ ww \mid w \in \{a,b\}^* \}$.
Between the words $w$ is no delimeter, so I don't know, how my TM can know where the first $w$ ends and the second $w$ begins.
Is there a trick for this?
Here is a sketch for how a deterministic machine might work:
One way I have read of is to first check the length of the string, and if it is odd, reject the string.
Then We could put some special character (e.g. c
) at the end of the entire string and copy the entire string to the other side of the special character and then apply the algorithm for checking $a^nb^n$.
I also found another method explained as a pseudo code in this pdf, which changes the first half of the string to some other substitute variables and then compares them.
An important thing to recognize is that you are only concerned with deciding if your input $x$ can be written as $ww$. That is, you want if decide $\exists w (x=ww)$.
There are many ways you can go about this, and honestly, there is even a large variety of easy ways to go about it. If you just have to describe the Turing machine in words (like, you don't have to construct a detailed diagram), then pretty much any of them would be sufficient. If you have to draw a diagram, here are some things you might want to consider:
If you are allowed to use nondeterminism, as was commented, you should take advantage of this. You can nondeterministically guess where there half-way point of your input is, and then check to see if the first segment matches the second segment. Likewise, you can always just guess what $w$ is and then check to see that your input tape looks like $ww$.
If you can't use nondeterminism, you can always emulate it by trying all possible middle points or writing down all possible $w$'s, stopping at a provably reasonable time, of course. You can, as a previous answer mentions, count the length of your input $x$, then use that to compute the middle point.
Some other considerations that are typical when one is a assigned problems like these deals with how many tapes your machine has. If you Turing machine only has one tape, guessing $w$ might be foolish, and you would be much better off guessing or finding the middle.
I hope this is sufficient. The tricky thing about this kind of question is, either you don't have to fully describe the Turing machine, in which case, there are lots of nice and short answers, or you do have to fully describe the Turing machine, in which case, you will have to do a nice little bit of work to convert one of these short descriptions into a diagram.