CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 4 · Turing Machines

Lesson 4.1.1 · Item 66 of 91

The Turing machine: tape, head, states, halting

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. Classify { aⁿbⁿcⁿ }.
    Stuck? Peek at 3.4.4 Drill: regular, DCFL, CFL or not CFL?
    • Ladder: bounded → regular; one comparison, no guess → DCFL; one comparison with a guess → CFL; two comparisons / crossing / copy / squares → not CFL.
    • “or” of comparisons → CFL not DCFL; “and” → not CFL.
    • Always check finiteness and collapses (unions that become a*b*).

    Read lesson 3.4.4

  2. What is an instantaneous description of a PDA?
    Stuck? Peek at 3.3.1 Stack primer and the push-down automaton
    • PDA (Q, Σ, Γ, δ, q₀, Z₀, F); δ(q, a|ε, X) ⊆ Q × Γ*; label a, X/γ (γ = ε pop, X keep, YX push).
    • ID (q, w, γ), top first; ⊢ one move, ⊢* many.
    • Nondeterministic by default; ε-moves still see the stack.

    Read lesson 3.3.1

  3. What are the three possible outcomes of a computation?
    Stuck? Peek at 0.1.1 What “computation” means
    • Machine: reads a finite input symbol by symbol, changes mode, ends with yes (accept) / no (reject) — or may never end.
    • Decision problem: a question whose answer is yes or no for every input.
    • Machines differ by memory: finite modes → pile of plates → endless notebook → beyond all machines.
    • Finite memory works iff the fact you must carry stays bounded (even/odd, remainder, “seen x?”). Unbounded counts/comparisons break it.

    Read lesson 0.1.1

The Hook

Imagine a clerk with a pencil, an eraser and an endless strip of squared paper. They look at one square at a time, may overwrite it, move one square left or right, and follow a finite rulebook. In 1936 Alan Turing argued that anything a person can compute by rote can be done this way. That clerk is the Turing machine (TM) — the model behind every computer, and the machine whose limits Phase 5 explores.

Predict First

A PDA could only touch the top of its stack. What two abilities does a tape add that a stack lacks?

Core Concept

Prediction check

The head can move back over what was written (read anywhere, not only the top), and it can overwrite any cell. The input itself sits on the tape and can be marked, erased, re-read many times.

stack (PDA)
access only at the top; the input is read once, left to right
tape (TM)
move left and right; read and overwrite any cell; re-read the input
The upgrade.

The machine

A TM has a finite set of states, an infinite tape of cells (initially the input followed by blanks □), and a head on the first input cell. Each step: read the symbol under the head; based on (state, symbol) write a symbol, move L or R, and change state.

steps illustration
Read, write, move, change state.

Formal definition

TM M = (Q, Σ, Γ, δ, q₀, □, F): states Q, input alphabet Σ, tape alphabet Γ ⊇ Σ ∪ {□}, blank □ ∈ Γ − Σ, start q₀, accepting states F, and
δ : Q × Γ → Q × Γ × {L, R} (a partial function).

The standard (deterministic) TM has at most one move per (state, symbol). Many books (and GATE) use a single accept state q_acc and a reject state q_rej instead of F. The machine halts when it enters an accepting/rejecting state, or when no move is defined (treated as reject).

partmeaning
Qfinite set of states
Σ ⊆ Γinput alphabet inside the tape alphabet
□blank, fills the rest of the tape
δ(q, X) = (p, Y, D)in q reading X: write Y, move D ∈ {L, R}, go to p
q_acc / q_rejhalting states
The 7-tuple at a glance.

Instantaneous descriptions

An ID is written α q β: tape contents α β (ignoring the endless blanks), current state q, head on the first symbol of β.

Example: X q1 bc means tape “Xbc”, state q1, head on b. A move δ(q1, b) = (q2, Y, R) gives X Y q2 c.

flowplay illustration
The same run as IDs: the state is written just left of the scanned cell.

Three outcomes

  • Accept: reaches an accepting state.
  • Reject: reaches the reject state or gets stuck (no move).
  • Loop: runs forever, never halting.

L(M) = strings M accepts. Strings outside L(M) are either rejected or looped on — and an observer watching a long run cannot always tell which is happening. That gap is the heart of Phase 5.

A recognizer that loops: accepts a*, loops on “ab…”

States: q0, q1, qa

Transitions: q0>q0: a/a,R; q0>q1: b/b,L; q1>q0: a/a,R; q0>qa: □/□,R

Accepts a*; rejects “b”; but on “ab” it walks right, left, right, left forever. Run “ab” to the end: the simulator gives up after 3000 steps.

Putting it together

  • A TM reads, writes and moves on an unbounded tape under a finite rulebook.
  • IDs α q β record configurations.
  • On any input it accepts, rejects, or loops — and looping is not rejecting.

Visual

tape:   … □ □ [a] b  c  □ □ …          finite control
                 ▲                      ┌────────┐
                head ───────────────────┤ state q│   δ(q, a) = (p, X, R)
                                        └────────┘   write X, move right, go to p

Worked Examples

Easy

From ID ab q0 ba with δ(q0, b) = (q1, a, L), what is the next ID?

Show the full solution

Overwrite b with a, move left onto the second b: a q1 baa.

Medium

Why can a TM accept { aⁿbⁿcⁿ } while a PDA cannot?

Show the full solution

It can return to the start and cross off one a, one b, one c per pass, re-reading the tape as many times as needed. A stack is destroyed as it is read.

GATE-level

A TM M halts on input w after exactly 10 moves and never moves left of cell 1. What is the largest number of tape cells it can have visited? Can it loop on some other input?

Show the full solution

At most 11 cells (start cell plus one new cell per move). Yes — halting on one input says nothing about others; TMs may loop on some inputs.

GATE Traps

  • A TM that does not halt has not rejected — it has given no verdict.
  • The input is on the tape; there is no separate read-only input.
  • δ is partial: an undefined move means the machine halts (reject unless in an accepting state).
  • GATE often uses single accept/reject states; F-based definitions are equivalent.

Memory Hook

A Turing machine is a clerk with an endless notebook, a pencil and an eraser — the most a rule-following clerk can ever do.

Connect the Dots

Now design TMs: crossing off symbols, copying strings, doing arithmetic in unary.

Self-Test

  1. MCQ

    In a standard TM, δ has the form:

    1. Q × Σ → Q
    2. Q × Γ → Q × Γ × {L, R}
    3. Q × Σ × Γ → Q × Γ*
    4. Q → Γ
  2. MSQ

    Which outcomes are possible for a TM on some input?

    1. accept
    2. reject
    3. run forever
    4. accept and reject
  3. MCQ

    ID a q3 bc means:

    1. state q3, head on a
    2. state q3, head on b
    3. state q3, head on c
    4. tape is q3
  4. NAT

    tmLoop above: how many of the inputs ε, a, b, ab, aa are accepted?

    Write your answer before opening the key.

Rule Card

  • TM (Q, Σ, Γ, δ, q₀, □, F), δ : Q × Γ → Q × Γ × {L,R} (partial).
  • ID α q β (head on first of β). Outcomes: accept, reject (or stuck), loop.
  • Tape: read/write anywhere, unbounded. L(M) = accepted strings.

Concept Ledger

  • Turing machine (TM)
  • tape, head, blank □
  • tape alphabet Γ
  • TM transition δ(q, X) = (p, Y, D)
  • ID α q β
  • halting: accept / reject / loop

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. Not context-free.
  2. (state, unread input, stack top-first).
  3. Halt and accept, halt and reject, run forever.

Self-test answers

  1. B — Read, write, move.
    • A: DFA.
    • C: PDA.
    • D: No.
  2. ABC — Three outcomes.
    • D: A deterministic run ends one way.
  3. B — The state precedes the scanned symbol.
    • A: a is left of the head.
    • C: c is further right.
    • D: No.
  4. 3 — ε, a, aa.

Flashcards

  1. TM transition function type?
    Reveal answerδ : Q × Γ → Q × Γ × {L, R}
  2. Three possible TM outcomes?
    Reveal answerAccept, reject, loop forever.
  3. What does ID α q β mean?
    Reveal answerTape αβ, state q, head on the first symbol of β.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.