4.6.13 · D3Theory of Computation

Worked examples — Turing machines — formal definition, computation, configurations

3,658 words17 min readBack to topic

The scenario matrix

Every worked example below is tagged with the cell it covers. Read this table first, then watch each cell get filled.

Cell The scenario class Covered by
C1 Normal accept — head walks right, halts on a blank Example A
C2 Normal reject — machine reaches Example B
C3 Empty input (head reads a blank immediately) Example C
C4 Left-edge move ( at cell 0) — head must stay put, not crash Example D
C5 Overwrite under the head, then move (tape actually changes) Example D
C6 Looping forever (never halts) — no accept, no reject Example E
C7 undefined / partial transition (implicit reject) Example F
C8 Word problem — a decidable language, checked end-to-end Example G
C9 Exam twist — recognizer that loops on a non-member Example H

Example A — Cell C1 (normal accept)

Figure — Turing machines — formal definition, computation, configurations

Figure s02 — alt-text: four stacked tape rows, each [0][0][0][⊔]. A red arrow (the head) points down at cell 0 in the top row, cell 1 in the next, cell 2 in the third, and cell 3 (the blank) in the bottom row where the state label reads q_acc. The red head marches one cell right per row — this is exactly steps 1→2→3→4 below.

  1. Start configuration is (, state , , head on the first 0).
    • Why this step? Every computation begins at with the head on the first input symbol — that's the definition of the start configuration. This is the top row of figure s02 (red head over cell 0).
  2. Read 0, apply : write 0 back, move right ().
    • Why? Move-right rule: the symbol we just wrote (0) joins the left part , and the state slides onto the next cell. This is the second row of s02: the red head has stepped to cell 1.
  3. Same rule twice more:
    • Why? Each 0 triggers the identical transition (rows 3 and 4 of s02, red head at cells 2 then 3). When the right part becomes empty, the head is now reading a blank — recall fills the tape past the input.
  4. Read , apply :
    • Why? This is a halting configuration — the state is (bottom row of s02, labelled q_acc), so the machine stops and says yes. ✓

Verify: input length , so right-moves over 0s plus blank step yields total. Final state . Accepts. ✓


Example B — Cell C2 (normal reject)

Figure — Turing machines — formal definition, computation, configurations

Figure s03 — alt-text: one tape row [1][0][0] with a red head arrow pointing down at cell 0 (the 1), state label q0. A red annotation arrow points from the 1 to the words "first symbol is 1 → q_reject, HALT", and black text notes "the 00 is never read". This is step 2 below.

  1. Start: (, state , , head on the 1).
    • Why? Head on the first symbol 1 — the red head in figure s03.
  2. Read 1, apply :
    • Why? We reached — a halting state (the red "→ q_reject, HALT" annotation in s03). The machine stops immediately and says no, even though 00 is still unread.

Verify: the string starts with 1, so it should be rejected — matches. Notice a TM, unlike a DFA, does not need to read the whole string to reject. Rejects. ✓


Example C — Cell C3 (empty input)

Figure — Turing machines — formal definition, computation, configurations

Figure s04 — alt-text: one tape row of four blank cells [⊔][⊔][⊔][⊔], red head arrow pointing down at cell 0, state label q0. A red annotation arrow points from cell 0 to "empty input: whole tape is blanks, head on cell 0"; black text reads "blank rule fires → q_accept". This is step 1 below.

  1. Start configuration. On empty input the tape is all blanks, so cell 0 already holds . Writing the head-symbol explicitly, the start configuration is — that is, , state , and (head reading the blank at cell 0, exactly the red head in figure s04).
    • Why? By our convention, when the input part would be empty we make the leading blank explicit and write rather than a bare ; the two mean the same thing, but shows precisely which symbol the head reads.
  2. Read , apply :
    • Why? The blank transition fires on step one (the "blank rule fires" note in s04). Halting state reached.

Verify: length- input right-moves over 0s blank step yield total. Accepts . ✓ (This machine recognizes , and , so accepting is correct.)


Example D — Cell C4 + C5 (left-edge move and overwrite)

Figure — Turing machines — formal definition, computation, configurations

Figure s01 — alt-text: two tape rows. Top row [1][#][0] with a red head over cell 1 (#), state q3. A black arrow points down to the bottom row [1][Y][0] with the red head over cell 0 (1), state q5. Two red annotations: "overwrite # → Y" pointing at the middle cell, and "move LEFT: head lands on cell 0 (left edge)" pointing at cell 0. This is step 1 below.

  1. Apply :
    • Why? Overwrite (C5): the # under the head becomes Y (the red "overwrite # → Y" note in s01). Move left () rule: the head steps onto the symbol immediately to its left, which is 1, so the new configuration is , state , (head on the 1). Look at figure s01: the red head jumps from the middle cell down to cell 0.
  2. Now suppose — another left () move, but the head is already at cell 0.
    • Why? (C4) The tape does not extend left of cell 0. By convention the head stays put — it does not crash, does not throw an error. Only the state changes (here ; the cell is rewritten 11, so the tape is unchanged). This is the left-edge special case from the parent note, and the red "head lands on cell 0" marker in s01 is exactly where the clamp bites.

Verify: after step 1 the tape reads 1Y0 and the head is at index 0. After step 2 the tape still reads 1Y0 and the head is still at index 0, because the clamp gives . ✓


Example E — Cell C6 (looping forever)

Figure — Turing machines — formal definition, computation, configurations

Figure s05 — alt-text: two tape rows, both [0][⊔], each labelled q0. In the top row the red head is on cell 0 (the 0); in the bottom row the red head is on cell 1 (the ). A red curved arrow labelled "move R" goes top→bottom, and a red curved arrow labelled "move L" goes bottom→top, forming a closed loop. Black text notes "never reaches a halting state". This matches steps 1–3 below.

  1. (read 0, , move right).
    • Why? Standard move-right (); the right part becomes just the blank, so the head now reads (top→bottom, the "move R" arrow in figure s05).
  2. (read , , move left).
    • Why? Move-left (): the head steps back left onto the 0. The tape is unchanged and the state is still (bottom→top, the "move L" arrow in s05).
  3. We are back at — the exact start configuration.
    • Why this matters? The machine cycles between two configurations forever (the closed red loop in s05). It never halts — neither accepts nor rejects. This is exactly the "gap" that makes recognizable weaker than decidable, and the seed of the Halting Problem.

Verify: the configuration at even step counts is always ; a period- cycle. Halting states encountered . Loops. ✓


Example F — Cell C7 (undefined / partial )


Example G — Cell C8 (word problem, decided end-to-end)


Example H — Cell C9 (exam twist: recognizer that loops)


Recall

Recall On empty input

, how do we write the start configuration and what does the head read? — the head is at cell 0 reading a blank (the whole tape is blank). ::: , head reading a blank at cell 0 In the notation , where does the state sit? ::: Between and — immediately before the head-symbol (the first symbol of ). Never . A left () move at cell 0 does what? ::: The head stays at cell 0 (left-edge convention) — it never crashes. A missing (undefined) transition means the machine does what? ::: Halts in by convention — implicit reject. Entering or causes what to happen? ::: The machine halts immediately — no further steps. A machine that reaches on members but loops on non-members is a ...? ::: recognizer (Turing-recognizable), not a decider. What makes the palindrome TM a decider rather than only a recognizer? ::: Every pass strictly shrinks the unmarked middle, so it always halts.


See also: Church-Turing Thesis, Nondeterministic Turing Machines, Multitape Turing Machines, Pushdown Automata.