CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 4 · Turing Machines

Lesson 4.1.2 · Item 67 of 91

Designing Turing machines

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

On this page

Recall warm-up

  1. What does δ(q, X) = (p, Y, L) do?
    Stuck? Peek at 4.1.1 The Turing machine: tape, head, states, halting
    • 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.

    Read lesson 4.1.1

  2. Why is aⁿbⁿcⁿ not a CFL?
    Stuck? Peek at 3.4.3 Pumping lemma for CFLs
    • L CFL ⇒ ∃p ∀z ∈ L, |z| ≥ p: z = uvwxy, |vwx| ≤ p, |vx| ≥ 1, uvⁱwxⁱy ∈ L ∀i ≥ 0. p = 2ᵏ (CNF, k variables).
    • Non-CFL: aⁿbⁿcⁿ, ww, aⁿbᵐcⁿdᵐ, #a=#b=#c, a^{n²}, a^{prime}, aⁱbʲcᵏ (i<j<k).
    • Unary CFL ⇒ regular. Complement of ww is a CFL.

    Read lesson 3.4.3

  3. How does a DFA track divisibility by k?
    Stuck? Peek at 1.1.3 DFA design patterns
    Language (|w| = k pattern)Minimal states
    starts with wk + 2
    contains w / ends with wk + 1
    |x| ≡ r mod nn
    |x| = k, |x| ≤ kk + 2
    |x| ≥ kk + 1
    #a mod m and/or #b mod nm·n (typical)
    binary value ≡ 0 mod k, k oddk
    binary ÷ 2ʲj + 1
    k-th symbol from start fixedk + 2

    Divisibility update: r ← (base·r + digit) mod k.

    Read lesson 1.1.3

The Hook

TM design is programming with a pencil: mark what you have used, walk back, repeat. Three patterns cover GATE: crossing off (matching counts), copying (shuttling symbols across), and arithmetic on unary or binary numbers.

Predict First

How many passes over the tape does the cross-off TM for aⁿbⁿcⁿ make on a³b³c³?

Core Concept

Prediction check

Three marking passes (one per a), each walking right then back, plus a final check pass. Each pass costs O(n) moves, so O(n²) in total.

steps illustration
Cross-off on aabbcc.

Pattern 1 — crossing off

Mark one symbol of each kind per pass with a new tape symbol (X, Y, Z); walk back to the leftmost unmarked symbol; repeat; finally check nothing unmarked remains. Works for aⁿbⁿcⁿ, aⁿbⁿ, #a = #b = #c, ww (cross off matching symbols in the two halves after finding the middle).

TM for aⁿbⁿcⁿ (mark one a, one b, one c per pass)

States: q0, q1, q2, q3, q4, qa

Transitions: q0>q1: a/X,R; q1>q1: a/a,R | Y/Y,R; q1>q2: b/Y,R; q2>q2: b/b,R | Z/Z,R; q2>q3: c/Z,L; q3>q3: a/a,L | b/b,L | Y/Y,L | Z/Z,L; q3>q0: X/X,R; q0>q4: Y/Y,R; q4>q4: Y/Y,R | Z/Z,R; q4>qa: □/□,R; q0>qa: □/□,R

The full machine. Try abc, aabbcc (accept) and aabbc, acb (reject).

Pattern 2 — copying

To turn w into w#w: repeatedly mark the leftmost unmarked symbol of w (remember it in the state — finitely many symbols, so finitely many “carrying” states), walk to the end, write it, walk back. Finally restore the marks. The state carries one symbol at a time — finite memory is enough for the carrying; the tape stores the rest.

steps illustration
Copying: the state remembers one symbol while the head travels.

Pattern 3 — unary arithmetic

Numbers as 1ⁿ. Addition 1ᵐ01ⁿ → 1ᵐ⁺ⁿ: replace the separator 0 by 1, go to the end, erase one 1. Multiplication: for each 1 of the first number, copy the second number to the output (copying inside a loop). Binary increment: go to the right end, flip trailing 1s to 0, the first 0 (or blank) to 1.

steps illustration
Two arithmetic machines — press Run to end inside each.

TMs as function computers

A TM computes f if, started on w, it halts with f(w) on the tape. Functions computed by TMs that halt on every input are the (total) computable functions.

input w on tape
TM runs
halts with f(w) on tape
Deciding a language = computing a yes/no function.

Putting it together

  • Cross-off, copy and arithmetic patterns cover TM design questions.
  • Extra tape symbols are the TM’s scratch marks.
  • A TM computes a function by halting with the answer on its tape.

Visual

aⁿbⁿcⁿ cross-off, one pass:
 [a] a b b c c   →   X a [b] b c c   →   X a Y b [c] c   →   X a Y b Z c   (walk back to X, step right)
 when q0 sees Y: scan right over Y Z; blank ⇒ accept; any a/b/c left ⇒ reject.

Worked Examples

Easy

In the aⁿbⁿcⁿ TM, what happens on input aabc?

Show the full solution

Pass 1 marks one a, b and c: X a Y Z. Pass 2 marks the second a, then q1 skips Y and meets Z with no b left to mark — no move is defined ⇒ reject.

Medium

Time complexity of the cross-off TM for aⁿbⁿcⁿ?

Show the full solution

n passes × O(n) moves = O(n²).

GATE-level

Which can a TM do but no PDA can? (i) accept aⁿbⁿcⁿ (ii) accept ww (iii) accept aⁿbⁿ (iv) compute the sum of two unary numbers

Show the full solution

(i), (ii) need a TM. (iii) a PDA suffices. (iv) is a function computation; PDAs don’t compute functions in this sense, TMs do. Answer: (i), (ii), (iv).

GATE Traps

  • Marking uses extra tape symbols (Γ ⊋ Σ) — that is allowed and essential.
  • The cross-off machine is O(n²); some questions ask for running time.
  • A missing move halts (reject); design every case explicitly.

Memory Hook

TM design = a librarian with sticky notes: mark, walk, mark, walk back.

Connect the Dots

Would more tapes, more heads, or guessing make TMs stronger? No — the next lesson shows every reasonable variant has the same power, and introduces a weaker cousin with a bounded tape.

Self-Test

  1. MCQ

    Running time of the cross-off TM for aⁿbⁿcⁿ:

    1. O(n)
    2. O(n log n)
    3. O(n²)
    4. O(2ⁿ)
  2. MSQ

    Which languages can the cross-off idea handle?

    1. aⁿbⁿcⁿ
    2. #a = #b = #c
    3. aⁿbⁿ
    4. any finite language
  3. NAT

    tmInc on input 0111: how many 1s are in the output?

    Write your answer before opening the key.

  4. MCQ

    In the copying TM, where is the symbol being carried remembered?

    1. on a stack
    2. in the state
    3. in a second tape
    4. nowhere

Rule Card

  • Cross-off: mark X/Y/Z per pass, walk back; O(n²) for aⁿbⁿcⁿ.
  • Copy: carry one symbol in the state, append, return.
  • Unary +: replace separator, erase one 1. Binary +1: trailing 1s → 0, first 0/□ → 1.
  • TM computes f: halts with f(w) on the tape.

Concept Ledger

  • crossing-off technique
  • copying technique
  • unary arithmetic TM
  • computable function

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. In q reading X: write Y, move left, go to p.
  2. The pumping window touches at most two of the three blocks.
  3. r ← (2r + b) mod k.

Self-test answers

  1. C — n passes of length O(n).
    • A: Too fast for one tape.
    • B: Not this design.
    • D: Too slow.
  2. ABCD — All are decidable; cross-off or direct scanning.
  3. 1 — 0111 + 1 = 1000.
  4. B — Finitely many symbols ⇒ finitely many carrying states.
    • A: No stack.
    • C: One tape suffices.
    • D: It must be remembered.

Flashcards

  1. How does a TM accept aⁿbⁿcⁿ?
    Reveal answerCross off one a, one b, one c per pass; accept if all are marked.
  2. Where does a copying TM remember the carried symbol?
    Reveal answerIn its finite state.
  3. Time of the one-tape cross-off TM for aⁿbⁿcⁿ?
    Reveal answerO(n²).

Ready for the next idea?

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