Introduction
A Turing machine (TM) is a finite-state controller with a doubly infinite (or one-way infinite) tape and a read/write head. It is the standard model of general-purpose computation. Languages recognized by TMs are the recursively enumerable (r.e.) languages; languages decided by TMs that always halt are the recursive (decidable) languages. The working core is the definitions, simple TM designs, variants (multitape, nondeterministic) and the Church-Turing thesis at statement level.
Prerequisites
- Pushdown Automata: limited auxiliary memory (stack) versus unrestricted tape.
Core concepts
Formal definition
A TM is with tape alphabet containing the blank , input alphabet , and
A step reads the tape cell under the head, writes a symbol, moves one cell left or right, and updates the state. Computation accepts by entering and rejects by entering .
Configurations
A configuration means tape contents (infinite blanks beyond), state , head on the first symbol of . One step: if then ; if then . On a one-way infinite tape a left move in the leftmost cell leaves the head where it is (Sipser's convention).
Three outcomes
On input a TM accepts (reaches ), rejects (reaches , or in HMU's convention halts with no move defined), or loops (runs forever). Looping is not rejection: an observer can never be sure that a long run will not still accept.
Recognizers versus deciders
- Recognizer. Accepts every string in , and either rejects or loops on strings not in . is r.e.
- Decider. Always halts; accepts iff the string is in . is recursive (decidable).
Every decidable language is r.e.; the converse is false (for example is r.e. but undecidable).
Variants
Multitape TMs, nondeterministic TMs, and TMs with stay-option heads all recognize the same class of languages as single-tape deterministic TMs (Sipser 3.2; HMU 8.4). Time bounds change; language power does not.
| Model | Power | Cost of simulation by a 1-tape DTM |
|---|---|---|
| -tape TM | = TM | steps become |
| Nondeterministic TM | = TM (both for recognizing and for deciding) | steps become (breadth-first search of the computation tree) |
| Stay option, two-way infinite or semi-infinite tape, multiple heads, 2-D tape | = TM | polynomial |
| Two-stack PDA; queue automaton; 2-counter machine | = TM | two stacks hold the tape left and right of the head |
| PDA (one stack); 1-counter machine | CFL or smaller | not universal |
| Linear bounded automaton (tape limited to the input) | CSL | the membership problem is decidable |
| TM that never writes, or that only moves right | regular | a read-only two-way head adds no power (2DFA = DFA) |
| Enumerator (prints strings, possibly forever) | RE | prints iff a TM recognizes |
A language is decidable iff some enumerator prints it in string order (shortlex). A finite automaton with a stack is not a TM; with two stacks it is.
How it works
High-level design macros
TMs are described at a high level in exams: "scan right to the first , cross it off, scan right to the first ," and so on. Storage in the finite state holds a constant amount of data; the tape holds unbounded data.
Example: recognize
Repeatedly cross off one , one , one from left to right; accept when nothing but crossed symbols remain; reject on mismatch. Example 1 gives the full transition table and a trace.

In Figure 1 the state labels and are and of the table in Example 1: the step drawn is .
Algorithms and pseudocode
TM-STEP(M, config)
1 read symbol under head
2 apply delta to get (new_state, write, dir)
3 write symbol; move head; set state
4 if state is accept or reject: haltPractice both a high-level TM description and step-by-step transition traces.
Mathematical explanation
Church-Turing thesis
Every effectively computable function is computable by a Turing machine. It is a thesis, not a theorem: it identifies the informal notion of algorithm with TM computability. All standard programming languages are TM-equivalent in power.
Encoding machines
Finite descriptions of TMs can be encoded as strings (or integers). That encoding enables universal machines and undecidability proofs in Decidability and Undecidability.
Worked examples
Example 1:
Tape alphabet ; becomes , becomes , becomes . Any pair not listed goes to .
| State | Reads | Write, move, next | Meaning |
|---|---|---|---|
| cross the leftmost | |||
| no left: check the rest | |||
| accept | empty input () | ||
| same, | skip to the first | ||
| cross it | |||
| same, | skip to the first | ||
| cross it, turn back | |||
| same, | return left | ||
| next round | |||
| only 's, then 's | |||
| accept | all counts matched |
Trace on aabbcc (first round): . The whole run accepts after 23 steps. On the machine takes exactly steps, so it runs in time on inputs of length ; it halts on every input, so it is a decider. It rejects abcc (in it reads ) and aabbc (in it reaches looking for a second ).
Example 2:
Find the middle (mark off matching ends, or use multitape copy); compare halves. Decidable.
Example 3: multitape simulation
A -tape TM simulates on one tape by interleaving tracks; the language is unchanged.
Example 4: nondeterministic TM
Guess a witness (for example a satisfying assignment) and verify deterministically. Nondeterministic TMs recognize and decide exactly the same languages as deterministic ones (Sipser 3.2); only the time can grow exponentially. An NTM decider must halt on every branch.
Example 5: loops
A TM whose only move is "on any symbol, move right" never halts, so it recognizes but is not a decider. The language is still decidable, by a different TM that rejects at once. Decidability is a property of the language (some TM decides it), not of one machine.
Example 6: closure, and "L and its complement both RE"
- Decidable languages are closed under union, intersection, complement, concatenation and star. RE languages are closed under union, intersection, concatenation and star, but not complement.
- For union of two recognizers, run them alternately one step at a time (dovetailing); running to completion first fails when loops.
- Theorem. If and are both RE, then is decidable: run both recognizers in parallel; exactly one accepts, and it must halt. Hence is not RE.
- Four groups. Call co-RE when is RE. The theorem says RE and co-RE together give exactly the decidable languages, so every language falls in exactly one of four groups.
| Group | Example | Argument |
|---|---|---|
| decidable (recursive) | a TM runs on for steps and always halts | |
| RE but not co-RE | , | the universal TM recognizes , which is undecidable by diagonalization; is recognized by simulation and is undecidable because ; an undecidable RE language is not co-RE, by the theorem |
| co-RE but not RE | , | is the complement of an RE language and is not RE, by the theorem; is RE (dovetail over all strings and accept when one is accepted), and , so is not RE |
| neither RE nor co-RE | , so it is not RE; , so and it is not co-RE |
- The reductions. For a pair let be the TM that ignores its own input, runs on and accepts if accepts. Then if accepts , and otherwise. Let reject everything and accept everything.
- maps to .
- maps to .
- maps to .
- "Not RE" alone does not place a language: is not RE but is co-RE, while is neither.
Example 7: counting argument
TMs have finite descriptions, so there are countably many. The set of languages over is the power set of a countable set, which is uncountable (diagonalization). Therefore most languages are not RE. The diagonal language is an explicit example.
Important properties and observations
- Tape is unbounded but only finitely many non-blank cells appear at any finite time.
- Acceptance needs only reach ; the tape contents at accept can be anything.
- PDA TM in power ( separates them).
- Universal TM: a TM with .
Common misconceptions.
- "TMs always halt." Only deciders do.
- "Nondeterministic TMs recognize more languages." They do not.
- "Infinite tape means infinite time is allowed for a decision." Decisions must halt in finite time.
- "A TM with a two-way read-only tape is more powerful than a DFA." It accepts only regular languages.
- "A two-stack PDA is just a PDA." Two stacks simulate a tape, so it is as powerful as a TM.
- "Rejecting and looping are the same." For a recognizer they both mean "not in ", but only a halting reject can be observed.
GATE examination perspective
- RECOGNIZE VS DECIDE. Keep the words apart: a recognizer may loop on strings outside ; a decider halts on every input.
- HIGH-LEVEL DESCRIPTIONS. Write clear phases; do not invent 50-state tables unless asked.
- VARIANTS PRESERVE LANGUAGES. Quote the equivalence.
- SEPARATION EXAMPLES. not CFL but decidable.
- MODEL POWER TABLE. Two stacks, a queue, or two counters equal a TM; one stack does not; read-only TMs are finite automata.
- COMPLEMENT RULE. RE and RE implies decidable; so if is RE but not decidable, is not RE.
- FOUR GROUPS. Decidable; RE not co-RE (); co-RE not RE (, ); neither (). Place a language by checking both and .
- STEP COUNTING. Crossing-off machines take quadratic time on one tape; a second tape makes linear.
Summary
Sources
- M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 3.1 (Turing machines), Section 3.2 (variants: multitape, nondeterministic, enumerators), Section 3.3 (the definition of algorithm), Section 4.2 (undecidability; the diagonalization method).
- J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley, Section 8.2 (the Turing machine), Section 8.3 (programming techniques for TMs), Section 8.4 (extensions to the basic TM), Section 8.5 (restricted TMs: semi-infinite tapes, multistack machines, counter machines).
- P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning, Section 9.1 (the standard Turing machine), Section 10.1 to 10.5 (other models: variations, multitape, nondeterministic, universal TM, linear bounded automata), Section 11.1 (recursive and recursively enumerable languages).