Theory of Computation – Automata & Computability Comprehensive Notes
Computation and Computability
Computation (in Theory of Computation – TOC) is any task that can be executed by a calculator or computer. In TOC we build an abstract machine and ask three meta-questions:
Can the machine perform the task?
For which problems does the machine succeed?
Where are its limitations?
Why Study Computability Theory?
• Limits of computation – some problems are inherently unsolvable by any algorithm. • Classifying problems – we distinguish: – Decidable (algorithm exists). – Undecidable (no algorithm can ever exist). • Programming-language foundations – grammars, compilers, interpreters rely on formal models from computability. • Algorithmic guidance – we only optimise after we confirm a problem is solvable. • Comparing computational models – finite automata, pushdown automata, Turing machines. • Bridge to complexity theory – once we know a problem is computable we ask how much time/space it costs. • Ethical & practical implication – prevents wasting resources on the impossible and underpins reliability proofs in safety-critical systems.
Mathematical Modelling and Automata
Natural language is ambiguous; mathematics gives precision, abstraction and formal reasoning. Automata are the simplest such models. Each automaton is a triple of:
States – finite memory.
AlphabetΣ – finite set of input symbols.
Transitionsδ – rules mapping (state,input) → state. They model sequential devices (switches, vending machines), software (lexers, parsers) and hardware (sequential circuits).
Basics of Automata Theory
• Study of abstract machines (automata) and the languages they recognise. • Central notions:
Symbol – single character, digit, icon, etc.
AlphabetΣ – finite, non-empty set of symbols, e.g. Σ=0,1 or ASCII.
String / word – finite sequence of symbols from Σ. Example: 01110.
Empty stringϵ – length 0.
Length∣w∣ – number of symbols in string w.
Powers of an alphabet: Σk = set of strings of length k. Σ0=ϵ, Σ1=Σ.
Kleene starΣ∗=⋃k≥0Σk – all finite strings. Σ+=Σ∗∖ϵ.
Concatenation: if x=a<em>1…a</em>m and y=b<em>1…b</em>n then xy=a<em>1…a</em>mb<em>1…b</em>n.
Languages and Problems
A languageL over Σ is any subset L⊆Σ∗. Examples:
ϵ,01,0011,000111,… – n zeros followed by n ones.
Equal numbers of 0’s and 1’s.
Binary representations of prime numbers. Languages can be finite (e.g., all binary strings of length 2) or infinite (e.g., all strings starting with a).
Problem-view: Given w∈Σ∗, decide whether w∈L. A machine that solves this decision problem *recognises* L.
Illustrative Finite State Machines
ON/OFF Switch
States ON,OFF, alphabet push, start OFF, toggling transition. Demonstrates the minimal concept of state memory.
Coffee Vending Machine
States: S<em>0 (idle), S</em>1 (coin), S2 (dispense). Alphabet insertcoin,selectcoffee. Transition table included in transcript. Shows how automata encode interaction order.
• Exactly one next state for every q and a∈Σ; no ϵ moves.
Processing a String
Given w=a<em>1a</em>2…a<em>n, start in q</em>0. Recursively compute q<em>i=δ(q</em>i−1,a<em>i). If q</em>n∈F → accept, else reject. Language of the DFA = all accepted strings.
Example: Substring 01
Language L=x01y∣x,y∈0,1∗. DFA states represent "how close" we are to having seen 01: • q<em>0 – none seen. • q</em>2 – last symbol was 0. • q<em>1 – have already seen 01 (accepting). Transitions built accordingly; full tuple A=(q</em>0,q<em>1,q</em>2,0,1,q<em>0,q</em>1,δ).
Common DFA Exercises
Strings ending with a (2 states).
∣w∣≥2 over a,b (accept all of length ≥2).
∣w∣≤2.
∣w∣=2.
Minimal DFA for even-length binary strings (two-state modulo-2 counter).
Nondeterministic Finite Automata (NFA)
• δ:Q×Σ→2Q – may return set of states (incl. empty set). • Machine branches; conceptually explores all paths in parallel.
Guess & Verify Paradigm
– Guess (branch) at nondeterministic choice points. – Verify deterministically along each branch. Input is accepted if any branch ends in F after whole input.
Formal Definition
Tuple Q,Σ,q0,F,δ with set-valued δ.
Example NFA for Strings Ending in 01
Adds nondeterministic "try now" arc so machine can jump into a two-state checker when it guesses the final 01 has started. Threads that get stuck simply die; acceptance needs one live accepting thread.
ϵ-NFA (NFA with Free Moves)
Special transitions labelled ϵ allow state changes without consuming input.
Acceptance: There exists a path consisting of input symbols plus any number of ϵ moves from q0 to some f∈F.
Processing Example “ba”
Start q<em>0ϵq</em>1, read b to stay in q<em>1, read a to reach q</em>1,q<em>2 → q</em>2 is final → accept.
Eliminating ϵ Moves
Compute ϵ-closure(q) – all states reachable from q via only ϵ.
For each state q and symbol a: – take ϵ-closure(q); – follow a transitions; – take ϵ-closure$ again → new transition.
A state becomes final in the new NFA if its \epsilon−closurecontainsanoldfinal.<br>Workedexamplewithstates{q0,q1,q_2}andalphabet{a}givenintranscript.</p></li></ol><h3id="be5b703e−e4e8−419b−a4d5−32388f928f11"data−toc−id="be5b703e−e4e8−419b−a4d5−32388f928f11"collapsed="false"seolevelmigrated="true">ConvertingNFAtoDFA–Subset(Powerset)Construction</h3><p>EveryNFAhasan<strong>equivalent</strong>DFA(samelanguage)eventhoughNFAmayappearmorepowerful.<br>Algorithm:</p><ol><li><p><strong>DFAstates</strong>=subsetsofNFAstates(2^{|Q|}possible).</p></li><li><p><strong>Startstate</strong>=\epsilon−closure(q_0^{NFA}).</p></li><li><p>ForeachDFAstateSandinputa:<br>\delta{DFA}(S,a) = \epsilon−closure\Big(\bigcup{q\in S} \delta_{NFA}(q,a)\Big).</p></li><li><p>DFAacceptingstates=thosesubsetscontainingatleastoneNFAfinalstate.</p></li></ol><p>Tinysample:NFAwithq0 \xrightarrow{a} q0, q1; $q1$ accepting. DFA has two states A={q0}(non−final)andB={q0,q_1}(final)withtransitionA\xrightarrow{a}B, \; B\xrightarrow{a}B.</p><h3id="a6f906e9−f84b−4131−a1e8−c500f76bffb8"data−toc−id="a6f906e9−f84b−4131−a1e8−c500f76bffb8"collapsed="false"seolevelmigrated="true">DFAMinimization</h3><p>Goal:smallestDFArecognisingalanguage.</p><ol><li><p><strong>Removeunreachable</strong>states(graphreachabilityfromq_0).</p></li><li><p><strong>Table−fillingmethod</strong>:markdistinguishablepairs(finalvsnon−final).Iterativelymarkpairswhosetransitionsleadtoalready−distinguishedpairs.</p></li><li><p><strong>Merge</strong>unmarked(equivalent)states.</p></li><li><p>RebuildDFA.<br>Exampleintranscriptshows4−stateDFAalreadyminimalbecauseeverypairbecamedistinguishable.</p></li></ol><h3id="577e008d−281f−4d8c−8a27−294fa56faa41"data−toc−id="577e008d−281f−4d8c−8a27−294fa56faa41"collapsed="false"seolevelmigrated="true">PracticalApplications</h3><p>•<strong>Textsearch/patternmatching</strong>–NFAsencodethepattern,DFAsperformfastlinearscanning(e.g.,grep).<br>•<strong>Keywordrecognition</strong>inlexicalanalysis–compiler’slexerusesaDFAwhosestatesrepresentlongest−prefixmatches.Examplekeywordset{if,int,while}producedstatesq0\dots q9withdeterministicedges;acceptingstatesq2,q4,q_9.<br>•<strong>Hardwarecontrol</strong>(on/off,vendingmachine).<br>•<strong>Networkprotocolvalidation</strong>,<strong>UIworkflows</strong>,<strong>regularexpressionengines</strong>.</p><h3id="dcdb2583−8460−4522−9dba−766b14ee9afc"data−toc−id="dcdb2583−8460−4522−9dba−766b14ee9afc"collapsed="false"seolevelmigrated="true">ConnectionstoFurtherTopics</h3><p>•OncealanguageisbeyondDFApower(e.g.,balancedparentheses)wemoveto<strong>pushdownautomata</strong>.<br>•UndecidablepropertiesappearattheTuring−machinelevel(e.g.,HaltingProblem).<br>•Complexityclasses(P,NP,PSPACE$$) build on computability: first ensure solvability, then measure resources.