Automata and Computability
1. Finite State Machines (FSM)
Section titled “1. Finite State Machines (FSM)”Deterministic Finite Automaton (DFA)
Section titled “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”
Section titled “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)
Section titled “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)
Section titled “NFA with Epsilon Transitions (ε-NFA)”An ε-NFA additionally allows transitions on the empty string ε (changing state without consuming Input).
2. DFA-NFA Equivalence
Section titled “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.
3. Regular Expressions
Section titled “3. Regular Expressions”Definition
Section titled “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
Section titled “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
Section titled “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
Section titled “4. Turing Machines”Definition
Section titled “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
Section titled “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
Section titled “Example: TM that accepts L={anbn∣n≥0}L = \{a^n b^n \mid n \geq 0\}L={anbn∣n≥0}”Algorithm:
- If tape is empty, accept
- Find the leftmost
aReplace withXMove right to find the leftmostbReplace 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
Section titled “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
Section titled “6. The Halting Problem”Definition
Section titled “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
Section titled “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
Section titled “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
Section titled “8. P vs NP”Definitions
Section titled “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
Section titled “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
Section titled “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
Section titled “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)
Section titled “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
Section titled “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``10Or 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
0Going right to find rightmost - : Saw
1Going 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.
Common Pitfalls
Section titled “Common Pitfalls”Misunderstanding the difference between a stack (LIFO) and a queue (FIFO) in data structure applications.
Confusing an algorithm with a program. An algorithm is a step-by-step procedure, not its implementation in code.
Neglecting to normalise database designs, leading to data redundancy and update anomalies.
Mixing up Big O, Big , and Big notation. Big O is an upper bound, not necessarily tight.
Common Mistakes
Section titled “Common Mistakes”Assuming NFAs are more powerful than DFAs. NFAs and DFAs accept exactly the same class of languages (the regular languages). NFAs are more convenient to write but not more powerful. The subset construction converts any NFA to an equivalent DFA.
Misapplying the Pumping Lemma. The Pumping Lemma shows a language is NOT regular by contradiction — you must show that for any pumping length p, there exists a string that cannot be pumped. Students often try to prove a language IS regular using the Pumping Lemma, which is impossible.
Confusing semi-decidable with decidable. The halting problem is semi-decidable — you can build a machine that accepts when it halts, but you cannot always reject when it doesn’t halt (it would loop forever). Decidable problems always halt with the correct answer.
Confusing P with NP. P is the class of problems solvable in polynomial time. NP is the class whose YES-instances can be verified in polynomial time. P ⊆ NP, but whether P = NP is unknown. NP-complete problems are in NP but not known to be in P.
Drawing NFA transitions incorrectly. An NFA can have multiple transitions for the same input symbol from a single state, and can have ε-transitions (changing state without consuming input). DFAs have exactly one transition per symbol per state.
Summary
Section titled “Summary”The key principles covered in this topic are linked in the sub-pages above. Focus on understanding the definitions, applying the formulas or frameworks, and evaluating strengths and limitations of each approach.
Worked Examples
Section titled “Worked Examples”Worked examples demonstrating the application of key concepts are covered in the detailed sub-pages linked above.
Intuition
Section titled “Intuition”At its core, computability theory asks a deceptively simple question: what can a machine actually do? Imagine you have an infinitely powerful assistant who can follow instructions perfectly and never gets tired. The theory of computation draws a boundary around what that assistant could — and could not — accomplish, no matter how clever the instructions. Automata are the simplest models in this landscape: finite automata can only remember a limited amount of information (like a toggle switch), push-down automata add a stack for slightly more memory, and Turing machines get an unlimited tape. Each step up in power unlocks new categories of problems that become solvable.
The Church-Turing thesis ties this all together by claiming that the Turing machine — despite being a simple, mechanical device — captures everything we informally mean by “computable.” Think of it like this: if you can describe a step-by-step procedure that a human could follow with pencil and paper, then a Turing machine can simulate it. This is remarkable because it means all programming languages, no matter how fancy their features, are ultimately equivalent in computational power. The differences between languages are about convenience and efficiency, not about what they can fundamentally compute.
Some problems, however, remain beyond reach. The halting problem — determining whether an arbitrary program will eventually stop or run forever — is famously undecidable. No algorithm can solve it for all possible inputs, and this sets a hard ceiling on what automated tools can guarantee. This insight has real consequences: it explains why perfect bug detectors, perfect optimisers, and perfect type-checkers are impossible. Recognising these limits is just as important as understanding what machines can do.