patternMinor
Turing machine for unary encoded quadratic numbers
Viewed 0 times
numbersunaryencodedformachineturingquadratic
Problem
I want to design a turing machine that accepts strings of the form $0^{n^2}$ where $n \geq 1$ and I want to give an implementation description for this. So I am thinking that the algorithm can go something like this: If we have $0^{1^2}$, we can just cross off that only $0$ and accept. If we have $0^{2^2}$, we can first scan and cross off two zeros and then scan again and cross off the last two zeros since there are four zeros total. And then for $0^{3^2}$, we have $9$ zeros, so in three scans we can just cross off three zeros.
So can anyone tell me if I have the right idea and how I can put this into an implementation description? What I can't think of is, how would it know though that it has just one zero, or 4, or 9, or 16 and so on?
So can anyone tell me if I have the right idea and how I can put this into an implementation description? What I can't think of is, how would it know though that it has just one zero, or 4, or 9, or 16 and so on?
Solution
Imagine writing a "real" program like this:
It's pretty clear that this can not work: there are infinitely many
Think about how you would solve the problem in procedural pseudo code, without using high level API/abstractions, and working on an infinite tape (instead of getting a string of fixed length). Then translate this idea into the formalism of Turing machines.
boolean isQuadratic(String s) {
if ( s == "0" )
return true
else if ( s == "00" )
return true
else if ( s == "000" )
return true
else if ...
...
else
return false
}It's pretty clear that this can not work: there are infinitely many
else if statements so you do not get a program at all. The same problem arises for Turing machines.Think about how you would solve the problem in procedural pseudo code, without using high level API/abstractions, and working on an infinite tape (instead of getting a string of fixed length). Then translate this idea into the formalism of Turing machines.
Code Snippets
boolean isQuadratic(String s) {
if ( s == "0" )
return true
else if ( s == "00" )
return true
else if ( s == "000" )
return true
else if ...
...
else
return false
}Context
StackExchange Computer Science Q#41416, answer score: 3
Revisions (0)
No revisions yet.