Recall warm-up
- 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.
- 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.
- 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 w k + 2 contains w / ends with w k + 1 |x| ≡ r mod n n |x| = k, |x| ≤ k k + 2 |x| ≥ k k + 1 #a mod m and/or #b mod n m·n (typical) binary value ≡ 0 mod k, k odd k binary ÷ 2ʲ j + 1 k-th symbol from start fixed k + 2 Divisibility update: r ← (base·r + digit) mod k.
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.
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).
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
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.
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.
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.
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
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.
Time complexity of the cross-off TM for aⁿbⁿcⁿ?
Show the full solution
n passes × O(n) moves = O(n²).
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
- MCQ
Running time of the cross-off TM for aⁿbⁿcⁿ:
- O(n)
- O(n log n)
- O(n²)
- O(2ⁿ)
- MSQ
Which languages can the cross-off idea handle?
- aⁿbⁿcⁿ
- #a = #b = #c
- aⁿbⁿ
- any finite language
- NAT
tmInc on input 0111: how many 1s are in the output?
Write your answer before opening the key.
- MCQ
In the copying TM, where is the symbol being carried remembered?
- on a stack
- in the state
- in a second tape
- 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
- In q reading X: write Y, move left, go to p.
- The pumping window touches at most two of the three blocks.
- r ← (2r + b) mod k.
Self-test answers
- C — n passes of length O(n).
- A: Too fast for one tape.
- B: Not this design.
- D: Too slow.
- ABCD — All are decidable; cross-off or direct scanning.
- 1 — 0111 + 1 = 1000.
- B — Finitely many symbols ⇒ finitely many carrying states.
- A: No stack.
- C: One tape suffices.
- D: It must be remembered.
Flashcards
- How does a TM accept aⁿbⁿcⁿ?
Reveal answer
Cross off one a, one b, one c per pass; accept if all are marked. - Where does a copying TM remember the carried symbol?
Reveal answer
In its finite state. - Time of the one-tape cross-off TM for aⁿbⁿcⁿ?
Reveal answer
O(n²).