Skip to main content

Automata and Computability

1. Finite State Machines (FSM)

Deterministic Finite Automaton (DFA)

Formal definition. A DFA is a 5-tuple M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) where:

  • QQ is a finite set of states
  • Σ\Sigma is a finite alphabet (input symbols)
  • δ:Q×ΣQ\delta: Q \times \Sigma \to Q is the transition function
  • q0Qq_0 \in Q is the start state
  • FQF \subseteq Q is the set of accepting (final) states

Language accepted: L(M)={wΣδ^(q0,w)F}L(M) = \{w \in \Sigma^* \mid \hat{\delta}(q_0, w) \in F\}

where δ^\hat{\delta} is the extended transition function (processes entire string).

Example: DFA that accepts strings ending in "01"

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) where:

  • Q={S,A,B}Q = \{S, A, B\} (S = start, A = saw 0, B = saw 01)
  • Σ={0,1}\Sigma = \{0, 1\}
  • F={B}F = \{B\}
01
SAS
AAB
BAS

Trace for "1101": S → S → A → B. Accepted. ✓

Trace for "1001": S → S → A → S → A →... wait, let me retrace.

"1001": S -(1)→ S -(0)→ A -(0)→ A -(1)→ B. Accepted. ✓

Non-Deterministic Finite Automaton (NFA)

Formal definition. An NFA is a 5-tuple M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) where:

  • δ:Q×ΣP(Q)\delta: Q \times \Sigma \to \mathcal{P}(Q) (maps to a set of states, not a single state)
  • All other components are the same as a DFA

An NFA accepts a string if there exists at least one path through the machine that ends in an accepting state.

NFA with Epsilon Transitions (ε-NFA)

An ε-NFA additionally allows transitions on the empty string ε (changing state without consuming input).

δ:Q×(Σ{ε})P(Q)\delta: Q \times (\Sigma \cup \{\varepsilon\}) \to \mathcal{P}(Q)


2. DFA-NFA Equivalence

Theorem (Rabin-Scott). For every NFA NN, there exists a DFA DD such that L(N)=L(D)L(N) = L(D). DFAs and NFAs accept exactly the same class of languages (the regular languages).

Proof (subset construction). Given NFA N=(QN,Σ,δN,q0,FN)N = (Q_N, \Sigma, \delta_N, q_0, F_N), construct DFA D=(QD,Σ,δD,q0,FD)D = (Q_D, \Sigma, \delta_D, q_0', F_D):

  1. QD=P(QN)Q_D = \mathcal{P}(Q_N) (states are subsets of QNQ_N)
  2. q0=εclosure({q0})q_0' = \varepsilon\mathrm{-closure}(\{q_0\})
  3. δD(S,a)=εclosure(qSδN(q,a))\delta_D(S, a) = \varepsilon\mathrm{-closure}\left(\bigcup_{q \in S} \delta_N(q, a)\right) for SQNS \subseteq Q_N
  4. FD={SQNSFN}F_D = \{S \subseteq Q_N \mid S \cap F_N \neq \emptyset\}

The DFA tracks the set of all states the NFA could be in. Since QNQ_N is finite, QDQ_D is finite (at most 2QN2^{|Q_N|} states). The DFA accepts exactly the same strings as the NFA. \square

Corollary. The class of regular languages is closed under union, intersection, complementation, concatenation, and Kleene star.

info

Board-specific

  • AQA requires finite state machines (FSMs) with state transition diagrams and tables, regular expressions, and Turing machines (conceptual understanding)
  • CIE (9618) requires finite state machines and Turing machines; may not emphasise regular expressions as heavily
  • OCR (A) requires finite state machines, state transition diagrams, regular expressions, and understanding of decidability
  • Edexcel covers finite state machines and basic automata theory

3. Regular Expressions

Definition

A regular expression defines a regular language using operators:

OperatorNameMeaningRegex
\emptysetEmpty setAccepts nothing
ε\varepsilonEmpty stringAccepts the empty stringε
aaLiteralAccepts the character aaa
RSR \cdot SConcatenationStrings from RR followed by SSRS
RSR \mid SAlternationStrings from RR or SSR|S
RR^*Kleene starZero or more repetitions of RRR*

Kleene's Theorem. A language is regular if and only if it can be described by a regular expression.

Examples

LanguageRegular Expression
Strings containing "abc".*(abc).*
Binary strings ending in "01"(0|1)*01
Strings of even length((0|1)(0|1))*
Strings with no consecutive 1s(0|10)*(1|ε)

Limitations of Regular Languages

Theorem. The language L={anbnn0}L = \{a^n b^n \mid n \geq 0\} is not regular.

Proof (Pumping Lemma). The Pumping Lemma for regular languages states: if LL is regular, then there exists a pumping length pp such that any string sLs \in L with sp|s| \geq p can be split into s=xyzs = xyz where:

  1. xyp|xy| \leq p
  2. y1|y| \geq 1
  3. xyizLxy^iz \in L for all i0i \geq 0

Choose s=apbps = a^p b^p. By condition 1, yy consists only of aa's. Pumping (i=0i = 0): xz=apybpxz = a^{p-|y|}b^p. Since y1|y| \geq 1, pypp - |y| \neq p, so apybpLa^{p-|y|}b^p \notin L. Contradiction. \square


4. Turing Machines

Definition

A Turing machine (TM) is a 7-tuple M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M = (Q, \Sigma, \Gamma, \delta, q_0, q_{accept}, q_{reject}) where:

  • QQ is a finite set of states
  • Σ\Sigma is the input alphabet (does not include the blank symbol)
  • Γ\Gamma is the tape alphabet (ΣΓ\Sigma \subseteq \Gamma, includes blank symbol \sqcup)
  • δ:Q×ΓQ×Γ×{L,R}\delta: Q \times \Gamma \to Q \times \Gamma \times \{L, R\} is the transition function
  • q0q_0 is the start state
  • qacceptq_{accept} is the accept state
  • qrejectq_{reject} is the reject state (qrejectqacceptq_{reject} \neq q_{accept})

Operation

  1. Tape is infinite in both directions, initialised with input followed by blanks
  2. Read/write head starts at the leftmost input symbol
  3. At each step: read the current symbol, consult δ\delta, write a symbol, move head left or right
  4. Accept if qacceptq_{accept} is reached; reject if qrejectq_{reject} is reached; may loop forever

Example: TM that accepts L={anbnn0}L = \{a^n b^n \mid n \geq 0\}

Algorithm:

  1. If tape is empty, accept
  2. Find the leftmost a, replace with X, move right to find the leftmost b, replace with X
  3. Return to the leftmost remaining a
  4. Repeat until no a remains
  5. If only X's and blanks remain, accept; otherwise reject

Formal transitions (partial):

StateReadWriteMoveNext State
q0q_0aaXXRRq1q_1
q0q_0XXXXRRq3q_3
q0q_0\sqcup\sqcupSSqacceptq_{accept}
q1q_1aaaaRRq1q_1
q1q_1XXXXRRq1q_1
q1q_1bbXXLLq2q_2
q2q_2aaaaLLq2q_2
q2q_2XXXXRRq0q_0
q3q_3XXXXRRq3q_3
q3q_3\sqcup\sqcupSSqacceptq_{accept}
q3q_3bbbbSSqrejectq_{reject}

5. The Church-Turing Thesis

Thesis (not provable — a thesis): Every effectively computable function is computable by a Turing machine.

Equivalently: any reasonable model of computation (lambda calculus, μ-recursive functions, modern programming languages) can compute exactly the same set of functions as a Turing machine.

This is a thesis, not a theorem — it cannot be proven because "effectively computable" is an informal concept. However, no counterexample has ever been found.


6. The Halting Problem

Definition

Halting problem: Given a description of a Turing machine MM and an input ww, determine whether MM halts (accepts or rejects) when run on ww.

Theorem (Turing, 1936). The halting problem is undecidable — no Turing machine can solve it for all possible inputs.

Proof by Contradiction

Assume a Turing machine HH exists that decides the halting problem:

H(M,w)={acceptifMhaltsonwrejectifMdoesnothaltonwH(M, w) = \begin{cases} \mathrm{accept} & \mathrm{if } M \mathrm{ halts on } w \\ \mathrm{reject} & \mathrm{if } M \mathrm{ does not halt on } w \end{cases}

Construct a new machine DD that uses HH:

D(M)={loopforeverifH(M,M)=accepthalt(reject)ifH(M,M)=rejectD(M) = \begin{cases} \mathrm{loop forever} & \mathrm{if } H(M, M) = \mathrm{accept} \\ \mathrm{halt (reject)} & \mathrm{if } H(M, M) = \mathrm{reject} \end{cases}

The contradiction: What happens when DD is run on its own description, DD?

  • If D(D)D(D) halts → H(D,D)H(D, D) accepted → DD should loop forever → contradiction
  • If D(D)D(D) loops forever → H(D,D)H(D, D) rejected → DD should halt → contradiction

Both cases lead to contradictions, so HH cannot exist. \square

Corollary. The halting problem is semi-decidable (recursively enumerable): we can build a machine that accepts when MM halts on ww, but it cannot always reject when MM doesn't halt (it would have to run forever).


7. Decidable and Undecidable Problems

CategoryDefinitionExample
DecidableA TM always halts with the correct answer"Is nn prime?"
Semi-decidableA TM halts on yes-instances; may loop on no-instancesHalting problem
UndecidableNo TM can solve it for all inputsHalting problem (full)
UnrecognisableNo TM even semi-decides itComplement of halting

8. P vs NP

Definitions

  • P: The class of decision problems solvable by a deterministic Turing machine in polynomial time O(nk)O(n^k) for some constant kk.
  • NP: The class of decision problems whose yes-instances can be verified by a deterministic Turing machine in polynomial time (given a certificate).

Relationship

PNP\mathrm{P} \subseteq \mathrm{NP}

Every problem in P is also in NP (if you can solve it in polynomial time, you can certainly verify a solution in polynomial time).

The P vs NP question: Is P=NP\mathrm{P} = \mathrm{NP}? This is one of the seven Millennium Prize Problems. Most computer scientists believe PNP\mathrm{P} \neq \mathrm{NP}.

NP-Complete Problems

A problem is NP-complete if:

  1. It is in NP
  2. Every problem in NP can be reduced to it in polynomial time

Examples of NP-complete problems:

  • Boolean satisfiability (SAT)
  • Travelling Salesman Problem (decision version)
  • Graph colouring
  • Knapsack problem
  • Subset sum

Implication: If any NP-complete problem is in P, then P=NP\mathrm{P} = \mathrm{NP}.

Examples of Problems in P

ProblemComplexity
SortingO(nlogn)O(n \log n)
Shortest path (Dijkstra)O((V+E)logV)O((V+E)\log V)
MST (Kruskal/Prim)O(ElogV)O(E \log V)
String matchingO(nm)O(nm) or O(n+m)O(n+m)
2-SATO(n+m)O(n + m)

Examples of Problems in NP (not known to be in P)

ProblemVerification
SATVerify assignment in O(n)O(n)
TSP (decision)Verify tour length in O(n)O(n)
Sudoku (n×n)Verify solution in O(n2)O(n^2)
Graph 3-colouringVerify colouring in O(V+E)O(V+E)

Problem Set

Problem 1. Design a DFA that accepts all binary strings containing an even number of 0s. Give the formal definition and draw the transition table.

Answer

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) where:

  • Q={q0,q1}Q = \{q_0, q_1\} (q0q_0 = even 0s seen, q1q_1 = odd 0s seen)
  • Σ={0,1}\Sigma = \{0, 1\}
  • q0q_0 is start state
  • F={q0}F = \{q_0\} (accept when even number of 0s)
01
q0q_0q1q_1q0q_0
q1q_1q0q_0q1q_1

Trace "110": q0q0q0q0q_0 \to q_0 \to q_0 \to q_0. Accept (0 zeros, even). ✓ Trace "101": q0q0q1q1q_0 \to q_0 \to q_1 \to q_1. Reject (1 zero, odd). ✓

Problem 2. Convert the following NFA to a DFA using the subset construction.

NFA: States {0,1,2}\{0, 1, 2\}, alphabet {a,b}\{a, b\}, start state 0, accepting state 2.

FromInputTo
0a\{0, 1\}
0b\{0\}
1a
1b\{2\}
2a
2b
Answer

DFA states (subsets of \{0, 1, 2\}):

Start: {0}\{0\}

From {0}\{0\}: a → \{0, 1\}, b → \{0\} From {0,1}\{0, 1\}: a → δ(0,a) ∪ δ(1,a) = \{0,1\} ∪ ∅ = \{0,1\}; b → δ(0,b) ∪ δ(1,b) = \{0\}\{2\} = \{0,2\} From {0,2}\{0, 2\}: a → δ(0,a) ∪ δ(2,a) = \{0,1\} ∪ ∅ = \{0,1\}; b → δ(0,b) ∪ δ(2,b) = \{0\} ∪ ∅ = \{0\} From ∅: a → ∅, b → ∅

Accepting states: any subset containing 2 → {0,2}\{0, 2\}.

DFA StateabAccept?
{0}\{0\}{0,1}\{0,1\}{0}\{0\}No
{0,1}\{0,1\}{0,1}\{0,1\}{0,2}\{0,2\}No
{0,2}\{0,2\}{0,1}\{0,1\}{0}\{0\}Yes
\emptyset\emptyset\emptysetNo

Problem 3. Write a regular expression for the language of all binary strings that do NOT contain the substring "11".

Answer

Any such string is a sequence of blocks, where each block is either 0, 10, or 1 (but the last 1 must not be followed by another 1).

Regular expression: (0|10)*(1|ε)

Explanation:

  • (0|10)* matches zero or more blocks of "0" or "10" (each 1 is followed by 0)
  • (1|ε) allows an optional trailing 1 (not followed by another 1)

Verification:

  • "" → matches (1|ε) with ε. ✓
  • "0" → matches (0|10)*(1|ε) with "0" and ε. ✓
  • "1" → matches (0|10)*(1|ε) with empty and "1". ✓
  • "10" → matches with "10" and ε. ✓
  • "0101" → matches with "0", "10", "1"... wait: "0101" = "0" + "10" + "1". ✓
  • "11" → cannot match (no way to have two consecutive 1s). ✓

Problem 4. Use the Pumping Lemma to prove that L={www{0,1}}L = \{ww \mid w \in \{0,1\}^*\} is not regular.

Answer

Assume LL is regular. Let pp be the pumping length. Choose s=0p10p1s = 0^p 1 0^p 1 (this is w=0p1w = 0^p1, ww=0p10p1ww = 0^p10^p1). Note s=2p+2p|s| = 2p + 2 \geq p. ✓

By the Pumping Lemma, s=xyzs = xyz with xyp|xy| \leq p and y1|y| \geq 1.

Since xyp|xy| \leq p, yy consists entirely of 0s from the first half. Say y=0ky = 0^k where 1kp1 \leq k \leq p.

Pump with i=0i = 0: xz=0pk10p1xz = 0^{p-k}10^p1.

Is this in LL? It would need to be wwww for some ww. The length is 2pk+22p - k + 2, which is odd when kk is odd, so it cannot be wwww (which always has even length). But even when kk is even, the first half is 0(pk/2)+10^{(p-k/2)+1}... actually, for xz=0pk10p1xz = 0^{p-k}10^p1 to be in L={ww}L = \{ww\}, we need the first half to equal the second half. The total length is 2p+2k2p + 2 - k. The first half is the first p+1k/2p + 1 - k/2 characters: 0pk10^{p-k}1. The second half is: 0k/20p1=0p+k/210^{k/2}0^p1 = 0^{p+k/2}1. For these to be equal, pk=p+k/2p-k = p+k/2, giving k=k/2k = -k/2, so k=0k = 0. But k1k \geq 1. Contradiction. ✓

Therefore, LL is not regular. \square

Problem 5. Describe a Turing machine that decides whether a binary string is a palindrome (reads the same forwards and backwards).

Answer

Algorithm:

  1. Read the leftmost symbol, remember it
  2. Move right to the rightmost non-blank symbol
  3. Compare: if they differ, reject; if same, replace both with blank
  4. Repeat until the tape is empty or one symbol remains
  5. Accept

States:

  • q0q_0: Start. Read leftmost symbol.
  • qaq_a: Saw 0, going right to find rightmost
  • qbq_b: Saw 1, going right to find rightmost
  • qcheck0q_{check0}: At rightmost, check if it's 0
  • qcheck1q_{check1}: At rightmost, check if it's 1
  • qreturnq_{return}: Going left to find leftmost
  • qacceptq_{accept}: Accept
  • qrejectq_{reject}: Reject

Key transitions:

  • q0q_0 reads 0: write blank, go right → qaq_a
  • q0q_0 reads 1: write blank, go right → qbq_b
  • q0q_0 reads blank: accept (empty string is palindrome)
  • qaq_a reads 0 or 1: move right
  • qaq_a reads blank: move left → qcheck0q_{check0}
  • qcheck0q_{check0} reads 0: write blank, move left → qreturnq_{return} (match!)
  • qcheck0q_{check0} reads 1: reject (mismatch!)
  • qreturnq_{return} reads 0, 1: move left
  • qreturnq_{return} reads blank: move right → q0q_0

This TM halts on all inputs (always reaches accept or reject), so the language of palindromes is decidable. ✓

Problem 6. Prove that if the halting problem were decidable, then every semi-decidable language would be decidable.

Answer

Proof. Let LL be a semi-decidable language. There exists a TM MLM_L that accepts ww if wLw \in L and loops forever if wLw \notin L.

If the halting problem were decidable, we could build a TM MM that decides LL:

  1. On input ww, run the halting decider HH on (ML,w)(M_L, w)
  2. If HH says MLM_L halts on ww: MLM_L will accept (since it only halts on members of LL), so run MLM_L on ww and accept
  3. If HH says MLM_L doesn't halt on ww: reject (since wLw \notin L)

This TM MM always halts and correctly decides LL. Since LL was arbitrary, every semi-decidable language would be decidable.

But we know the halting problem is undecidable, so there must exist semi-decidable languages that are not decidable (e.g., the halting problem itself). \square

Problem 7. Explain the difference between a decidable problem and a semi-decidable problem. Give an example of each.

Answer

Decidable: There exists a TM that halts on ALL inputs and correctly answers yes/no.

  • Example: "Given a DFA MM and a string ww, does MM accept ww?" — simulate MM on ww; it always halts.

Semi-decidable (recursively enumerable): There exists a TM that halts and accepts on yes-instances, but may loop forever on no-instances.

  • Example: "Given a TM MM and input ww, does MM halt on ww?" — run MM on ww; if it halts, accept. But if MM doesn't halt, our verifier loops forever.

Key difference: For semi-decidable problems, you can verify a "yes" answer in finite time, but you cannot always verify a "no" answer (the machine might just be taking a long time, or it might loop forever).

Problem 8. Is the complement of the halting problem semi-decidable? Explain.

Answer

No. The complement of the halting problem is not semi-decidable.

Proof. If both a language LL and its complement L\overline{L} were semi-decidable, then LL would be decidable (run both semi-decidable machines in parallel; one must eventually halt, giving the answer).

The halting problem is semi-decidable (run the TM and accept when it halts). If its complement were also semi-decidable, the halting problem would be decidable — but we proved it's not. Therefore, the complement of the halting problem is not semi-decidable. \square

Problem 9. Explain why the Travelling Salesman Problem (decision version: "Is there a tour of length ≤ k?") is in NP.

Answer

The TSP decision problem is in NP because a proposed solution (a tour) can be verified in polynomial time:

Certificate: A permutation of the nn cities (the proposed tour).

Verification algorithm:

  1. Check that the certificate is a valid permutation of all nn cities — O(n)O(n)
  2. Sum the distances between consecutive cities (and from last back to first) — O(n)O(n)
  3. Compare the total to kkO(1)O(1)

Total verification time: O(n)O(n), which is polynomial. Therefore, TSP is in NP. ✓

(Note: this does NOT mean TSP is in P. Verification is polynomial, but finding the tour may not be.)

Problem 10. State the Church-Turing thesis. Explain why it is a thesis and not a theorem. What would it mean if it were false?

Answer

Church-Turing Thesis: Every function that is effectively computable (can be computed by an algorithm) is computable by a Turing machine.

Why it's a thesis, not a theorem: "Effectively computable" is an informal, intuitive concept — it refers to any step-by-step procedure that a human could follow with pen and paper (or a computer could execute). Since this is not a mathematically precise definition, we cannot formally prove that Turing machines capture all of "computation." However, every reasonable model of computation proposed (lambda calculus, μ-recursive functions, register machines, modern programming languages) has been shown to be equivalent to Turing machines, providing overwhelming evidence for the thesis.

If it were false: There would exist an effectively computable function that no Turing machine could compute. This would mean our entire understanding of computation is fundamentally incomplete — there would be a type of computation that our current theoretical models cannot capture. It would revolutionise computer science and mathematics, as it would imply the existence of a "super-Turing" model of computation.

For revision on algorithms and complexity, see Complexity Analysis.

:::