Automata and Turing machines

O(n)·O(n)
q0, back to itself: 0, 10, 1q0 to q1: ␣␣q1, back to itself: 11q1 to qH: 0, ␣0, ␣q0q0q1q1qHqH
␣␣␣␣111111␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣-2-200224466881010121214141616181820202222TapePosition
  • Being read

The machine starts in state q0, with the head at the first digit of 111.

The machine starts in state q0, with the head at the first digit of 111.
  1. 1While reading a 0 or 1, move right to keep scanning for the end of the number.
  2. 2While reading a 0 or 1, move right to keep scanning for the end of the number.
  3. 3At the first blank past the number, move left: this is where the carry starts.
  4. 4While carrying and reading a 1, write 0 and keep moving left.
  5. 5When the carry reaches a 0, write 1 and stop: the carry is absorbed.
  6. 6If the carry reaches the blank left of the first digit, write a new leading 1 and stop.
Steps taken
0
Symbols written
0

Complexity

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

Binary incrementer

A Turing machine with three states and six transition rules. It scans right past every digit of a binary number to find the first blank cell past it, then walks back left, flipping each trailing 1 to a 0 — the carry — until it meets a 0 (which it flips to 1, absorbing the carry) or runs off the left end of the number entirely, in which case it writes a brand new leading 1 in the blank cell that was waiting there.

When it is the right choice

As the first thing to show anyone who thinks "Turing machine" necessarily means something large or intricate. This one does a real, checkable job — it computes n + 1 in binary, correctly, for every canonical binary number it accepts — with a transition table a reader can read in full on one screen.

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