Automata and Computability
1. Finite State Machines (FSM)
Deterministic Finite Automaton (DFA)
Formal definition. A DFA is a 5-tuple where:
- is a finite set of states
- is a finite alphabet (input symbols)
- is the transition function
- is the start state
- is the set of accepting (final) states
Language accepted:
where is the extended transition function (processes entire string).
Example: DFA that accepts strings ending in "01"
where:
- (S = start, A = saw 0, B = saw 01)
| 0 | 1 | |
|---|---|---|
| S | A | S |
| A | A | B |
| B | A | S |
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 where:
- (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).
2. DFA-NFA Equivalence
Theorem (Rabin-Scott). For every NFA , there exists a DFA such that . DFAs and NFAs accept exactly the same class of languages (the regular languages).
Proof (subset construction). Given NFA , construct DFA :
- (states are subsets of )
- for
The DFA tracks the set of all states the NFA could be in. Since is finite, is finite (at most states). The DFA accepts exactly the same strings as the NFA.
Corollary. The class of regular languages is closed under union, intersection, complementation, concatenation, and Kleene star.
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:
| Operator | Name | Meaning | Regex |
|---|---|---|---|
| Empty set | Accepts nothing | — | |
| Empty string | Accepts the empty string | ε | |
| Literal | Accepts the character | a | |
| Concatenation | Strings from followed by | RS | |
| Alternation | Strings from or | R|S | |
| Kleene star | Zero or more repetitions of | R* |
Kleene's Theorem. A language is regular if and only if it can be described by a regular expression.
Examples
| Language | Regular 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 is not regular.
Proof (Pumping Lemma). The Pumping Lemma for regular languages states: if is regular, then there exists a pumping length such that any string with can be split into where:
- for all
Choose . By condition 1, consists only of 's. Pumping (): . Since , , so . Contradiction.
4. Turing Machines
Definition
A Turing machine (TM) is a 7-tuple where:
- is a finite set of states
- is the input alphabet (does not include the blank symbol)
- is the tape alphabet (, includes blank symbol )
- is the transition function
- is the start state
- is the accept state
- is the reject state ()
Operation
- Tape is infinite in both directions, initialised with input followed by blanks
- Read/write head starts at the leftmost input symbol
- At each step: read the current symbol, consult , write a symbol, move head left or right
- Accept if is reached; reject if is reached; may loop forever
Example: TM that accepts
Algorithm:
- If tape is empty, accept
- Find the leftmost
a, replace withX, move right to find the leftmostb, replace withX - Return to the leftmost remaining
a - Repeat until no
aremains - If only
X's and blanks remain, accept; otherwise reject
Formal transitions (partial):
| State | Read | Write | Move | Next State |
|---|---|---|---|---|
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 and an input , determine whether halts (accepts or rejects) when run on .
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 exists that decides the halting problem:
Construct a new machine that uses :
The contradiction: What happens when is run on its own description, ?
- If halts → accepted → should loop forever → contradiction
- If loops forever → rejected → should halt → contradiction
Both cases lead to contradictions, so cannot exist.
Corollary. The halting problem is semi-decidable (recursively enumerable): we can build a machine that accepts when halts on , but it cannot always reject when doesn't halt (it would have to run forever).
7. Decidable and Undecidable Problems
| Category | Definition | Example |
|---|---|---|
| Decidable | A TM always halts with the correct answer | "Is prime?" |
| Semi-decidable | A TM halts on yes-instances; may loop on no-instances | Halting problem |
| Undecidable | No TM can solve it for all inputs | Halting problem (full) |
| Unrecognisable | No TM even semi-decides it | Complement of halting |
8. P vs NP
Definitions
- P: The class of decision problems solvable by a deterministic Turing machine in polynomial time for some constant .
- NP: The class of decision problems whose yes-instances can be verified by a deterministic Turing machine in polynomial time (given a certificate).
Relationship
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 ? This is one of the seven Millennium Prize Problems. Most computer scientists believe .
NP-Complete Problems
A problem is NP-complete if:
- It is in NP
- 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 .
Examples of Problems in P
| Problem | Complexity |
|---|---|
| Sorting | |
| Shortest path (Dijkstra) | |
| MST (Kruskal/Prim) | |
| String matching | or |
| 2-SAT |
Examples of Problems in NP (not known to be in P)
| Problem | Verification |
|---|---|
| SAT | Verify assignment in |
| TSP (decision) | Verify tour length in |
| Sudoku (n×n) | Verify solution in |
| Graph 3-colouring | Verify colouring in |
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
where:
- ( = even 0s seen, = odd 0s seen)
- is start state
- (accept when even number of 0s)
| 0 | 1 | |
|---|---|---|
| → | ||
Trace "110": . Accept (0 zeros, even). ✓ Trace "101": . Reject (1 zero, odd). ✓
Problem 2. Convert the following NFA to a DFA using the subset construction.
NFA: States , alphabet , start state 0, accepting state 2.
| From | Input | To |
|---|---|---|
| 0 | a | \{0, 1\} |
| 0 | b | \{0\} |
| 1 | a | ∅ |
| 1 | b | \{2\} |
| 2 | a | ∅ |
| 2 | b | ∅ |
Answer
DFA states (subsets of \{0, 1, 2\}):
Start:
From : a → \{0, 1\}, b → \{0\} From : a → δ(0,a) ∪ δ(1,a) = \{0,1\} ∪ ∅ = \{0,1\}; b → δ(0,b) ∪ δ(1,b) = \{0\} ∪ \{2\} = \{0,2\} From : 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 → .
| DFA State | a | b | Accept? |
|---|---|---|---|
| → | No | ||
| No | |||
| Yes | |||
| No |
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 is not regular.
Answer
Assume is regular. Let be the pumping length. Choose (this is , ). Note . ✓
By the Pumping Lemma, with and .
Since , consists entirely of 0s from the first half. Say where .
Pump with : .
Is this in ? It would need to be for some . The length is , which is odd when is odd, so it cannot be (which always has even length). But even when is even, the first half is ... actually, for to be in , we need the first half to equal the second half. The total length is . The first half is the first characters: . The second half is: . For these to be equal, , giving , so . But . Contradiction. ✓
Therefore, is not regular.
Problem 5. Describe a Turing machine that decides whether a binary string is a palindrome (reads the same forwards and backwards).
Answer
Algorithm:
- Read the leftmost symbol, remember it
- Move right to the rightmost non-blank symbol
- Compare: if they differ, reject; if same, replace both with blank
- Repeat until the tape is empty or one symbol remains
- Accept
States:
- : Start. Read leftmost symbol.
- : Saw
0, going right to find rightmost - : Saw
1, going right to find rightmost - : At rightmost, check if it's
0 - : At rightmost, check if it's
1 - : Going left to find leftmost
- : Accept
- : Reject
Key transitions:
- reads
0: write blank, go right → - reads
1: write blank, go right → - reads blank: accept (empty string is palindrome)
- reads
0or1: move right - reads blank: move left →
- reads
0: write blank, move left → (match!) - reads
1: reject (mismatch!) - reads
0,1: move left - reads blank: move right →
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 be a semi-decidable language. There exists a TM that accepts if and loops forever if .
If the halting problem were decidable, we could build a TM that decides :
- On input , run the halting decider on
- If says halts on : will accept (since it only halts on members of ), so run on and accept
- If says doesn't halt on : reject (since )
This TM always halts and correctly decides . Since 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).
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 and a string , does accept ?" — simulate on ; 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 and input , does halt on ?" — run on ; if it halts, accept. But if 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 and its complement were semi-decidable, then 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.
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 cities (the proposed tour).
Verification algorithm:
- Check that the certificate is a valid permutation of all cities —
- Sum the distances between consecutive cities (and from last back to first) —
- Compare the total to —
Total verification time: , 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.
:::