A deterministic Turing machine (TM) has a finite control and an infinite tape divided into cells. The input w∈Σ∗ is written on the tape, the rest of the tape holds blanks, and the head starts on the leftmost input symbol in the start state. In each step the machine reads the cell under the head, writes a symbol, moves the head one cell left or right, and changes state.
Formally M=(Q,Σ,Γ,δ,q0,B,F). Here Q is the finite set of states, Σ the input alphabet, Γ⊇Σ∪{B} the tape alphabet, B the blank (not in Σ), q0 the start state and F the set of accepting states. The transition function is δ:Q×Γ→Q×Γ×{L,R}, and it may be partial: if δ is undefined the machine halts. We assume no transition leaves an accepting state, so entering a state of F halts the machine.
Notation. Σ is the input alphabet, ε the empty string, ∣w∣ the length of w, L the complement of L with respect to Σ∗, and ⟨M⟩ a string encoding of the machine M; ⟨M,w⟩ encodes the pair of a machine and an input.
Convention used below. In transition tables a cell (p,c,D) means: go to state p, write c, move in direction D. An empty cell means δ is undefined, so the machine halts and rejects (unless the state is accepting). The start state is marked →, the accepting state *.
Design idea for L={anbn∣n≥1}. Repeatedly mark the leftmost unmarked a as X, run right to the leftmost unmarked b and mark it Y, then return to the leftmost unmarked a. When no a is left, check that only Y's remain.
Transition table for a^n b^n (tape alphabet a, b, X, Y, blank)
Trace on aabb: q0 marks the first a; q1 skips the second a and marks the first b; q2 walks back to the X and returns to q0; q0 marks the second a; q1 skips the Y and marks the second b; q2 walks back; q0 sees Y and goes to q3; q3 skips the Y's and reads a blank, so the machine enters q4 and accepts. On aab the machine gets stuck in q1 at the blank and rejects. On ε it rejects at once (q0 on blank is undefined), and on abab it rejects in q3 on reading a.