Automata and Turing machines

O(n²)·O(n)
start to seekR0: 00start to seekR1: 11start, back to itself: X, YX, Ystart to accept: ␣␣seekR0, back to itself: 0, 10, 1seekR0 to back1_0: X, Y, ␣X, Y, ␣seekR1, back to itself: 0, 10, 1seekR1 to back1_1: X, Y, ␣X, Y, ␣back1_0 to markL: 00back1_0 to reject: 11back1_0 to accept: X, YX, Yback1_1 to markL: 11back1_1 to reject: 00back1_1 to accept: X, YX, YmarkL, back to itself: 0, 1, X, YmarkL to start: ␣␣startstartseekR0seekR0seekR1seekR1back1₀back1₀back1₁back1₁markLmarkLacceptacceptrejectreject
␣␣␣␣11000011␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣-2-2002244668810101212141416161818TapePosition
  • Being read

The machine starts in state start, with the head at the first symbol of 1001.

The machine starts in state start, with the head at the first symbol of 1001.
  1. 1Look at the leftmost unmarked symbol: it is a 0, so mark it and remember 0.
  2. 2Look at the leftmost unmarked symbol: it is a 1, so mark it and remember 1.
  3. 3The leftmost symbol is already marked 0 — skip over it.
  4. 4The leftmost symbol is already marked 1 — skip over it.
  5. 5No unmarked symbols remain: every pair matched, so accept.
  6. 6Scan right, past an unmarked 0, looking for the rightmost unmarked symbol.
  7. 7Scan right, past an unmarked 1, looking for the rightmost unmarked symbol.
  8. 8Found the right edge: the symbol just left of it, already marked 0, is the rightmost unmarked one — step onto it.
  9. 9Found the right edge: the symbol just left of it, already marked 1, is the rightmost unmarked one — step onto it.
  10. 10Reached the blank past the end: step back left onto the rightmost unmarked symbol.
  11. 11Scan right, past an unmarked 0, looking for the rightmost unmarked symbol.
  12. 12Scan right, past an unmarked 1, looking for the rightmost unmarked symbol.
  13. 13Found the right edge: the symbol just left of it, already marked 0, is the rightmost unmarked one — step onto it.
  14. 14Found the right edge: the symbol just left of it, already marked 1, is the rightmost unmarked one — step onto it.
  15. 15Reached the blank past the end: step back left onto the rightmost unmarked symbol.
  16. 16The rightmost unmarked symbol is a 0, matching the remembered 0: mark it and scan left to repeat.
  17. 17The rightmost unmarked symbol is a 1, but the remembered symbol was 0: reject.
  18. 18Only one unmarked symbol remained and it is already marked 0 (the odd-length middle): accept.
  19. 19Only one unmarked symbol remained and it is already marked 1 (the odd-length middle): accept.
  20. 20The rightmost unmarked symbol is a 1, matching the remembered 1: mark it and scan left to repeat.
  21. 21The rightmost unmarked symbol is a 0, but the remembered symbol was 1: reject.
  22. 22Only one unmarked symbol remained and it is already marked 0 (the odd-length middle): accept.
  23. 23Only one unmarked symbol remained and it is already marked 1 (the odd-length middle): accept.
  24. 24Scan left, past an unmarked 0, back toward the start.
  25. 25Scan left, past an unmarked 1, back toward the start.
  26. 26Scan left, past a symbol already marked 0, back toward the start.
  27. 27Scan left, past a symbol already marked 1, back toward the start.
  28. 28Reached the start: step back onto the leftmost symbol and look for the next unmarked one.
Steps taken
0
Symbols marked
0

Complexity

BestO(n)
AverageO(n²)
WorstO(n²)
Extra spaceO(n)
n² at n=4 predicts 16; this run took 0.

Binary palindrome checker

A Turing machine using the standard mark-and-compare technique: repeatedly mark the leftmost unmarked symbol, scan right to find the rightmost unmarked symbol, compare the two (rejecting the instant they differ), mark the second one too if they match, then scan back left past everything already marked and repeat — until no unmarked symbols remain, which means every pair matched.

When it is the right choice

As the second machine on this tool, immediately after the binary incrementer, because it is noticeably bigger for a noticeably harder kind of task: deciding whether a whole string has a property, rather than computing one new tape from an old one.

How it works

Worth noticing

Cost

Best
O(n)
Average
O(n²)
Worst
O(n²)
Space
O(n)

Worth comparing

All automata and Turing machines