Turing Machine that finds even or odd length

12.3k views Asked by At

I have a question that I am stuck on:

Describe formally (i.e., by means of a transition function) a Turing machine which decides whether the input word a^n has an even or an odd length.

Would someone please be able to enlighten me on what I am being asked to do as I don't really understand it?!

Any help would be much appreciated, thanks.

2

There are 2 answers

0
Dylan On BEST ANSWER

Not sure if you are still looking for a solution or not, but I found one that solves it in linear time. Here are the transition functions that will produce a 1 on the output tape if even, and 0 otherwise.

(q_start start blank) --> (R S 1 q_test)
(q_test x 1 ) --> (R S 0 q_test)
(q_test x 0 ) --> (R S 1 q_test)
(q_test blank x) --> (S S x q_halt) 

x represents an letter of the given alphabet.

I alternate writing 1's and 0's untill we hit the end of the {0,1}* string. Once we hit a blank, we simply return and the value on the output tape is our answer.

0
arieljuod On

You need to design a Turing Machine that receives an input of a^n (a, aa, aaa, aaaa, aaaaa, aaaaaa, etc..., any a...a string) and decides if the length is odd or even. You should think of it as a question to decide: is the string length odd? then the answer would be YES or NO, if it's "NO" you imply that the length is even.

One answer I can imagine is, I'll explain with with an example (you do the formal design):

input: aaaaaaa (a^7)

>aaaaaaa_ #you start at the end and move to the left
        ^
>aaaaaaa #head is on an a
       ^
>aaaaaaY #write a yes
       ^
>aaaaaaY #move to the left
      ^
>aaaaaaY #head is on an a so, we write an N, go right, delete Y and move left twice
      ^
>aaaaaNY
      ^
>aaaaaNY
       ^
>aaaaaN_
       ^
>aaaaaN
      ^
>aaaaaN
     ^

Now you repeat the same process but with an Y (write an Y, move right, delete N, move left twice). After some steps you will have:

>aN #head on a, last write was N, so we write Y
 ^
>YN #go right
 ^
>YN #delete N
  ^
>Y_ #go left twice
  ^
>Y
 ^
>Y #now, head is on > (the beginning of the input) so we finished
^
>Y #move right twice and stop
 ^
>Y_
  ^

There, you got the answer Y to the question "is a^7's length ODD?"

Try the same idea with an even length and you should end up with

>N_
  ^

That's the idea I came up with, maybe you find a simpler machine, now you have to create the diagram or the tables to define it properly (this was just an example, not a definition)