Skip to content

Automata and Computability

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”

Section titled “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. ✓

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.

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)


Theorem (Rabin-Scott). For every NFA NNThere 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.


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.

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|ε)

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 pSo apybpLa^{p-|y|}b^p \notin L. Contradiction. \square


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 \GammaIncludes 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})
  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 δ\deltaWrite 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\}

Section titled “Example: TM that accepts L={anbn∣n≥0}L = \{a^n b^n \mid n \geq 0\}L={anbn∣n≥0}”

Algorithm:

  1. If tape is empty, accept
  2. Find the leftmost aReplace with XMove right to find the leftmost bReplace 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}

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.


Halting problem: Given a description of a Turing machine MM and an input wwDetermine 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.

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 wwBut it cannot always reject when MM doesn’t halt (it Would have to run forever).


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

  • 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).

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}.

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}.

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)

Section titled “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 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``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 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 + 2Which 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/2Giving k=k/2k = -k/2So 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 0Going right to find rightmost
  • qbq_b: Saw 1Going 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 wwRun 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 wwDoes 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 wwDoes 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.

  1. Misunderstanding the difference between a stack (LIFO) and a queue (FIFO) in data structure applications.

  2. Confusing an algorithm with a program. An algorithm is a step-by-step procedure, not its implementation in code.

  3. Neglecting to normalise database designs, leading to data redundancy and update anomalies.

  4. Mixing up Big O, Big Ω\Omega, and Big Θ\Theta notation. Big O is an upper bound, not necessarily tight.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

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 demonstrating the application of key concepts are covered in the detailed sub-pages linked above.

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.