Skip to content

Automata and Formal Languages

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

  • QQ = finite set of states
  • Σ\Sigma = input alphabet
  • δ:Q×Σ→Q\delta: Q \times \Sigma \to Q = transition function
  • q0∈Qq_0 \in Q = start state
  • F⊆QF \subseteq Q = set of accepting states

Language of MM: L(M)={w∈Σ∗:M accepts w}L(M) = \{w \in \Sigma^* : M \text{ accepts } w\}

Example: DFA for strings ending in “ab” over Σ={a,b}\Sigma = \{a, b\}:

States: {q0, q1, q2}
q0 → (a) → q1, q0 → (b) → q0
q1 → (a) → q1, q1 → (b) → q2
q2 → (a) → q1, q2 → (b) → q0
Start: q0, Accept: q2

Extended transition function: δ∗:Q×Σ∗→Q\delta^*: Q \times \Sigma^* \to Q

δ∗(q,ϵ)=q\delta^*(q, \epsilon) = q δ∗(q,wa)=δ(δ∗(q,w),a)\delta^*(q, wa) = \delta(\delta^*(q, w), a)

1.2 Nondeterministic Finite Automaton (NFA)

Section titled “1.2 Nondeterministic Finite Automaton (NFA)”

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

  • δ:Q×(Σ∪{ϵ})→2Q\delta: Q \times (\Sigma \cup \{\epsilon\}) \to 2^Q = transition function (returns a set of states)

Key difference from DFA: Multiple transitions per symbol, ϵ\epsilon-transitions allowed.

Example: NFA for strings containing “aba” over Σ={a,b}\Sigma = \{a, b\}:

States: {q0, q1, q2, q3}
q0 → (a) → {q0, q1}
q1 → (b) → q2
q2 → (a) → q3
Start: q0, Accept: q3

1.3 NFA to DFA Conversion (Subset Construction)

Section titled “1.3 NFA to DFA Conversion (Subset Construction)”

Convert NFA NN to equivalent DFA DD:

SUBSET_CONSTRUCTION(N):
D.states = 2^Q
D.start = ε-closure({q0})
mark D.start as unexplored
while unexplored states exist:
pick unexplored state S
for each symbol a in Σ:
T = ε-closure(∪ δ(q, a) for each q in S)
D.transition[S][a] = T
if T not yet in D.states:
add T as unexplored
mark S as explored
D.accept = {S : S ∩ F ≠ ∅}

Time: O(2n)O(2^n) states in worst case. Often much smaller in practice.

Minimize a DFA to the smallest equivalent DFA.

MINIMIZE(DFA):
// Remove unreachable states
remove states not reachable from start
// Partition into accepting and non-accepting
P = {F, Q \ F}
repeat:
P" = {}
for each group G in P:
split G into subgroups where
for all a in Σ: δ(p,a) and δ(q,a) are in same group of P
add subgroups to P'
until P' == P
return DFA with P' as states

Result: Unique minimal DFA (up to isomorphism). O(nlog⁡n)O(n \log n) with Hopcroft’s algorithm.

Why uniqueness holds (Myhill—Nerode argument). Define the indistinguishability relation on states: p∼qp \sim q iff for every string zz, δ∗(p,z)∈F  ⟺  δ∗(q,z)∈F\delta^*(p, z) \in F \iff \delta^*(q, z) \in F. Distinguishable states must remain in different groups of any correct partition; some zz separates them, and the refinement loop splits exactly when such a zz exists (by induction on ∣z∣|z|: after kk rounds, states are grouped together iff they agree on all strings of length ≤k\leq k; the loop terminates when no string separates any pair). So the fixed point groups states into exactly the ∼\sim-classes. After removing unreachable states, every ∼\sim-class is nonempty (each class contains the state a distinct residual language is recognised from), and the quotient DFA accepts the same language by construction. Any two minimal DFAs therefore both have one state per ∼\sim-class, start states corresponding to the class of ϵ\epsilon, transitions induced by the same class relation, and accepting states the class(es) in FF; a relabelling isomorphism. ■\blacksquare

Theorem. DFAs and NFAs recognize exactly the same class of languages: the regular languages.

DFA≡NFA≡Regular Expressions\text{DFA} \equiv \text{NFA} \equiv \text{Regular Expressions}

Proof. Every DFA is an NFA that ignores its nondeterminism (each transition returns a singleton set, no ϵ\epsilon-moves), so NFA⊆DFA\text{NFA} \subseteq \text{DFA} languages is immediate in one direction and DFA⊆NFA\text{DFA} \subseteq \text{NFA} is trivial. The substance is that subset construction preserves the language.

Correctness of subset construction. Let NN be an NFA and DD its subset-constructed DFA. Claim: after DD reads ww, its current state is exactly E(w)E(w); the ϵ\epsilon-closure of the set of states NN could occupy after reading ww. Induction on ∣w∣|w|. Base: E(ϵ)E(\epsilon) equals ϵ-closure({q0})\epsilon\text{-closure}(\{q_0\}), which is DD‘s start state by construction. Step: assume the claim for ww; on reading aa, DD transitions from E(w)E(w) to the ϵ\epsilon-closure of the union of δ(q,a)\delta(q, a) over q∈E(w)q \in E(w); which is precisely E(wa)E(wa), since NN‘s possible states after wawa are the ϵ\epsilon-closures of the aa-successors of its possible states after ww.

Acceptance follows: DD accepts ww iff E(w)∩F≠∅E(w) \cap F \neq \emptyset iff some accepting state of NN lies in E(w)E(w) iff NN accepts ww. So L(D)=L(N)L(D) = L(N), and the two models recognise the same languages. The regular-expression equivalence is completed by Thompson’s construction (RE→NFA\text{RE} \to \text{NFA}, by structural induction on the expression; each row of the table in §2.1 preserves the language, again by induction) and state elimination (DFA→RE\text{DFA} \to \text{RE}, whose elimination rule RikRkk∗Rkj∪RijR_{ik} \mathrel{R_{kk}}^* R_{kj} \cup R_{ij} records exactly the paths through qkq_k, so by induction on the eliminated set the final label enumerates all accepting paths). ■\blacksquare

Regular expressions over alphabet Σ\Sigma:

  • ∅\emptyset: Empty language.
  • ϵ\epsilon: Language {ϵ}\{\epsilon\}.
  • aa (for a∈Σa \in \Sigma): Language {a}\{a\}.
  • R1⋅R2R_1 \cdot R_2 (concatenation): {uv:u∈L(R1),v∈L(R2)}\{uv : u \in L(R_1), v \in L(R_2)\}.
  • R1∪R2R_1 \cup R_2 (union/alternation): L(R1)∪L(R2)L(R_1) \cup L(R_2).
  • R∗R^* (Kleene star): {w1w2⋯wk:k≥0,wi∈L(R)}\{w_1 w_2 \cdots w_k : k \geq 0, w_i \in L(R)\}.
  • R+=R⋅R∗R^+ = R \cdot R^*: One or more repetitions.

2.2 RE to NFA Conversion (Thompson’s Construction)

Section titled “2.2 RE to NFA Conversion (Thompson’s Construction)”
RE FormConstruction
∅\emptysetSingle non-accepting state
ϵ\epsilonStart = accept (single state)
aaStart → aa → accept
R1∪R2R_1 \cup R_2New start with ϵ\epsilon to starts of R1R_1 and R2R_2; accepts merge via ϵ\epsilon
R1⋅R2R_1 \cdot R_2Connect accept of R1R_1 to start of R2R_2 via ϵ\epsilon
R∗R^*New start/accept with ϵ\epsilon loops through RR

Properties:

  • RE has at most O(∣R∣)O(|R|) states in the NFA.
  • NFA may have ϵ\epsilon-transitions but no more than 2 outgoing transitions per state.
DFA_TO_RE(DFA):
rename states q1, q2, ..., qn
add new start state qs and new accept state qf
for each pair (qi, qj), eliminate states one by one
update transition labels using state elimination formula:
// Eliminating state qk:
// For each path qi → qk → qj:
// new label = (label(qi,qk)) (label(qk,qk))* (label(qk,qj)) ∪ label(qi,qj)

2.4 Closure Properties of Regular Languages

Section titled “2.4 Closure Properties of Regular Languages”

Regular languages are closed under:

OperationProof Method
UnionRE: R1∪R2R_1 \cup R_2; NFA: parallel construction
IntersectionDFA: product construction
ComplementDFA: swap accept/non-accept states
ConcatenationRE: R1⋅R2R_1 \cdot R_2
Kleene starRE: R∗R^*
ReversalRE: reverse expression; NFA: reverse arrows
DifferenceA∖B=A∩B‾A \setminus B = A \cap \overline{B}

If LL is a regular language, then there exists a constant pp (the pumping length) such that any string s∈Ls \in L with ∣s∣≥p|s| \geq p can be divided into s=xyzs = xyz satisfying:

  1. ∣y∣>0|y| > 0 (y is non-empty)
  2. ∣xy∣≤p|xy| \leq p
  3. xyiz∈Lxy^iz \in L for all i≥0i \geq 0

Proof. Let MM be a DFA for LL with pp states, and let s∈Ls \in L with ∣s∣≥p|s| \geq p. As MM reads ss it visits ∣s∣+1≥p+1|s| + 1 \geq p + 1 states (counting the start state), but MM has only pp distinct states; by the pigeonhole principle some state repeats among the first p+1p + 1 visited, say qi=qjq_i = q_j with i<j≤pi < j \leq p. Set

x=s1⋯si,y=si+1⋯sj,z=sj+1⋯s∣s∣.x = s_1 \cdots s_i, \qquad y = s_{i+1} \cdots s_j, \qquad z = s_{j+1} \cdots s_{|s|}.

Then ∣y∣=j−i≥1|y| = j - i \geq 1 and ∣xy∣=j≤p|xy| = j \leq p. The segment yy drives MM from qiq_i back to qiq_i; a loop. Reading the loop any number of times k≥0k \geq 0 leaves MM at qiq_i after xykxy^k, so MM ends on exactly the same state it would reading ss itself; an accepting state, since s∈Ls \in L. Hence xykz∈Lxy^kz \in L for all k≥0k \geq 0. Take pp to be MM‘s state count. ■\blacksquare

The three conditions have mechanical roles: ∣y∣>0|y| > 0 ensures pumping changes the string; ∣xy∣≤p|xy| \leq p pins the loop to the first pp symbols (this is where the pigeonhole applies); (3) says every pumping exponent stays in LL; so to use the lemma against a candidate language you must refute all divisions, not just one.

3.2 Using the Pumping Lemma (Proof by Contradiction)

Section titled “3.2 Using the Pumping Lemma (Proof by Contradiction)”

To prove LL is not regular:

  1. Assume LL is regular. Let pp be the pumping length.
  2. Choose a string s∈Ls \in L with ∣s∣≥p|s| \geq p (strategically).
  3. Show that for any division s=xyzs = xyz with ∣xy∣≤p|xy| \leq p, ∣y∣>0|y| > 0, some xyiz∉Lxy^iz \notin L.
  4. Contradiction → LL is not regular.

Example: L={anbn:n≥0}L = \{a^n b^n : n \geq 0\}

Let s=apbps = a^p b^p. Since ∣xy∣≤p|xy| \leq p, y=aky = a^k for some k≥1k \geq 1. Then xy0z=ap−kbp∉Lxy^0z = a^{p-k}b^p \notin L. Therefore LL is not regular.

Example: L={0n1n:n≥0}L = \{0^n 1^n : n \geq 0\}

Same approach. Not regular.

Example: L={wwR:w∈{0,1}∗}L = \{ww^R : w \in \{0,1\}^*\}

Choose s=0p11p0ps = 0^p 1 1^p 0^p. Pumping yy (within first pp symbols) breaks the palindrome structure.

LanguageNot Regular Because
{anbn:n≥0}\{a^n b^n : n \geq 0\}Need to count aa‘s vs bb‘s
{anbncn:n≥0}\{a^n b^n c^n : n \geq 0\}Need to match three counts
{ww:w∈Σ∗}\{ww : w \in \Sigma^*\}Need unbounded memory
{ap:p is prime}\{a^p : p \text{ is prime}\}Primes are non-regular
{w∈{a,b}∗:#a(w)=#b(w)}\{w \in \{a,b\}^* : \#_a(w) = \#_b(w)\}Need to count

A CFG is a 4-tuple G=(V,Σ,R,S)G = (V, \Sigma, R, S) where:

  • VV = finite set of variables (nonterminals)
  • Σ\Sigma = finite set of terminals (alphabet)
  • RR = finite set of production rules of form A→αA \to \alpha where A∈VA \in V, α∈(V∪Σ)∗\alpha \in (V \cup \Sigma)^*
  • S∈VS \in V = start variable

Language of GG: L(G)={w∈Σ∗:S⇒∗w}L(G) = \{w \in \Sigma^* : S \Rightarrow^* w\}

Balanced parentheses:

S → (S)
S → SS
S → ε

{anbn:n≥0}\{a^n b^n : n \geq 0\}:

S → aSb
S → ε

{anbncn:n≥0}\{a^n b^n c^n : n \geq 0\} is NOT context-free (proven by pumping lemma for CFLs).

Every production is of the form:

  • A→BCA \to BC (two variables)
  • A→aA \to a (one terminal)
  • S→ϵS \to \epsilon (only for start symbol)

Conversion:

  1. Eliminate ϵ\epsilon-productions (except S→ϵS \to \epsilon).
  2. Eliminate unit productions (A→BA \to B).
  3. Eliminate useless symbols (unreachable and non-generating).
  4. Convert remaining productions to CNF.

A parse tree for a string ww generated by a CFG:

  • Root: labeled SS
  • Internal nodes: labeled with variables
  • Leaves: labeled with terminals (left to right form ww)
  • Children of node AA: labeled with the right-hand side of a production A→αA \to \alpha

A CFG is ambiguous if some string has two or more different parse trees (equivalently, different leftmost derivations).

Example:

E → E + E
E → E * E
E → (E)
E → a

The string a+a∗aa + a * a has two parse trees: (a+a)∗a(a + a) * a and a+(a∗a)a + (a * a).

Unambiguous version (precedence):

E → E + T | T
T → T * F | F
F → (E) | a

Inherent ambiguity: Some CFLs have no unambiguous grammar (e.g., {aibjck:i=j or j=k}\{a^i b^j c^k : i = j \text{ or } j = k\}).

A PDA is a 6-tuple M=(Q,Σ,Γ,δ,q0,F)M = (Q, \Sigma, \Gamma, \delta, q_0, F) where:

  • Γ\Gamma = stack alphabet
  • δ:Q×(Σ∪{ϵ})×(Γ∪{ϵ})→2Q×(Γ∪{ϵ})\delta: Q \times (\Sigma \cup \{\epsilon\}) \times (\Gamma \cup \{\epsilon\}) \to 2^{Q \times (\Gamma \cup \{\epsilon\})}

Each transition: read input symbol (or ϵ\epsilon), pop stack symbol (or ϵ\epsilon), push symbol(s) (or ϵ\epsilon), change state.

Deterministic PDA (DPDA): For every configuration, at most one move is possible.

5.2 PDA for {anbn:n≥0}\{a^n b^n : n \geq 0\}

Section titled “5.2 PDA for {anbn:n≥0}\{a^n b^n : n \geq 0\}{anbn:n≥0}”
Q = {q0, q1, q2}, F = {q2}, Σ = {a,b}, Γ = {S, $}
δ(q0, a, $) = {(q0, a$)} // push a for each a read
δ(q0, a, a) = {(q0, aa)}
δ(q0, b, a) = {(q1, ε)} // pop a for each b read
δ(q1, b, a) = {(q1, ε)}
δ(q1, ε, $) = {(q2, $)} // accept when stack has only $

Theorem: CFGs and PDAs recognize the same class of languages: the context-free languages.

Proof. (CFG ⇒\Rightarrow PDA.) Given GG, build a PDA PP with three states; start, loop, accept; that works purely on the stack: push \$$ then S;intheloop,thetopofstackiseitheravariable; in the loop, the top of stack is either a variableA(popit,nondeterministicallypushtheright−handsideofanyproduction(pop it, nondeterministically push the right-hand side of any productionA \to \alpha)oraterminal) or a terminala(popit,consume(pop it, consumeafromtheinput);acceptwhenfrom the input); accept when$isexposed.Byinductiononderivationlength,thestackcontentsafteris exposed. By induction on derivation length, the stack contents afterkmovesareexactlythesententialformsreachablemoves are exactly the sentential forms reachablekstepsintoaleftmostderivation,withterminalsmatchedagainstinputinorder:thePDAacceptssteps into a leftmost derivation, with terminals matched against input in order: the PDA acceptswiffiffS \Rightarrow^* w.So. SoL(P) = L(G)$.

(PDA ⇒\Rightarrow CFG.) Given PDA PP, normalise so acceptance is by empty stack and each move pops then pushes at most two symbols. Variables are triples [q A q′][q\,A\,q'], read as “starting in state qq with AA on the stack, PP can consume some input and end in q′q' having popped AA with net stack effect nil below it”. For each transition producing net effect from state qq back to some q′′q'', add productions [q A q′]→a [q′′ B1 qm] [qm B2 q′][q\,A\,q'] \to a\,[q''\,B_1\,q_m]\,[q_m\,B_2\,q'] over all intermediate states qmq_m (this is where nondeterminism is absorbed; the choice of qmq_m encodes where the second symbol’s net-nil segment begins), and the base case [q A q]→ϵ[q\,A\,q] \to \epsilon. By induction on computation length, [q A q′]⇒∗w[q\,A\,q'] \Rightarrow^* w iff PP can go from qq to q′q' consuming ww while popping AA without disturbing the stack below it; instantiating with the start configuration gives L(G)=L(P)L(G) = L(P), up to the standard padding that empties the initial stack symbol. The double induction (on derivation length and computation length) is the labour; the construction above is the entire idea. ■\blacksquare

CFG≡PDA≡CFL\text{CFG} \equiv \text{PDA} \equiv \text{CFL}

Key difference from regular languages: DPDAs are strictly weaker than nondeterministic PDAs.

Regular=DPDA⊊NPDA=CFL\text{Regular} = \text{DPDA} \subsetneq \text{NPDA} = \text{CFL}
OperationClosed?
UnionYes
ConcatenationYes
Kleene starYes
IntersectionNo*
ComplementNo
Intersection with regularYes

*Not closed under general intersection, but closed under intersection with a regular language (using product of PDA and DFA).

6. Pumping Lemma for Context-Free Languages

Section titled “6. Pumping Lemma for Context-Free Languages”

If LL is a CFL, then there exists pp such that any s∈Ls \in L with ∣s∣≥p|s| \geq p can be divided into s=uvxyzs = uvxyz satisfying:

  1. ∣vy∣>0|vy| > 0 (v and y not both empty)
  2. ∣vxy∣≤p|vxy| \leq p
  3. uvixyiz∈Luv^ixy^iz \in L for all i≥0i \geq 0

The proof mirrors the regular case, with parse trees replacing DFA state traces. Let GG be a CFG for LL and bb the maximum number of symbols on any right-hand side. Set p=b∣V∣p = b^{|V|}, where ∣V∣|V| is the number of variables.

Take any s∈Ls \in L with ∣s∣≥p|s| \geq p and fix a smallest parse tree for ss. A tree of height hh has at most bhb^h leaves, so height <∣V∣< |V| would give ∣s∣<b∣V∣=p|s| < b^{|V|} = p; contradiction. So some root-to-leaf path contains at least ∣V∣+1|V| + 1 variables, and with only ∣V∣|V| variables in total, two occurrences on that path carry the same variable AA. Choose them so the lower occurrence is within the bottom ∣V∣+1|V| + 1 variables of the path.

Write the yield as s=u v x y zs = u\,v\,x\,y\,z, where vv and yy are the yields of the two AA-subtrees’ outer ring. Then:

  1. ∣vy∣≥1|vy| \geq 1: if both were empty, the two AA-subtrees would be identical, and excising the lower one would leave a smaller parse tree for ss; contradicting minimality.
  2. ∣vxy∣≤p|vxy| \leq p: vxyvxy is confined to the subtree rooted at the upper AA, whose height is at most ∣V∣+1|V| + 1, bounding its yield by b∣V∣+1≤p⋅bb^{|V|+1} \le p \cdot b; with b≥2b \geq 2 the standard bound is stated as ∣vxy∣≤p|vxy| \leq p by taking p=b∣V∣+1p = b^{|V|+1}.
  3. Pumping works by grafting: replacing the upper AA-subtree with the lower one gives uv0xy0zuv^0xy^0z; duplicating the lower inside the upper gives uv2xy2zuv^2xy^2z; induction on ii gives uvixyiz∈Luv^ixy^iz \in L for all i≥0i \geq 0. ■\blacksquare

Example: L={anbncn:n≥0}L = \{a^n b^n c^n : n \geq 0\} is not context-free.

Let s=apbpcps = a^p b^p c^p. Since ∣vxy∣≤p|vxy| \leq p, the substring vxyvxy cannot span all three letter types.

  • If vxyvxy contains only aa‘s and bb‘s: pumping breaks the aa-bb-cc balance.
  • If vxyvxy contains only bb‘s and cc‘s: same issue.
  • If vxyvxy contains only one letter type: pumping breaks all three counts.

Not CFL (require three matching counts or more):

LanguageWhy Not CFL
{anbncn:n≥0}\{a^n b^n c^n : n \geq 0\}Three matching counts
{aibjck:i>j>k}\{a^i b^j c^k : i > j > k\}Three ordered counts
{ww:w∈{a,b}∗}\{ww : w \in \{a,b\}^*\}Copy language (non-CFL)

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

  • QQ = states
  • Σ\Sigma = input alphabet (⊔∉Σ\sqcup \notin \Sigma, blank symbol)
  • Γ=Σ∪{⊔}\Gamma = \Sigma \cup \{\sqcup\} = tape alphabet
  • δ:Q×Γ→Q×Γ×{L,R}\delta: Q \times \Gamma \to Q \times \Gamma \times \{L, R\}
  • q0q_0 = start, qaccept,qrejectq_{\text{accept}}, q_{\text{reject}} = halting states

Operation: Read symbol under head, write symbol, move left/right, change state. Computation halts on accept or reject.

All are equivalent in power to the standard TM:

VariantDescription
Multi-tape TMMultiple tapes, each with its own head
Nondeterministic TMMultiple possible transitions
EnumeratorsPrint out strings of a language
Multi-dimensional tapeTape extended to 2D+ grid

Theorem: Multi-tape TMs, nondeterministic TMs, and standard TMs recognize the same class of languages.

Proof. (Multi-tape ⇒\Rightarrow single-tape.) Simulate kk tapes on one tape by storing them concatenated, separated by a marker #\#, with each head’s position marked by a dotted symbol a˙\dot{a}. One simulated step: sweep the tape left to right recording the kk marked symbols (in the state), then sweep back applying the kk writes and moves (shifting content right when a head needs a fresh blank). Each simulated step costs O(n)O(n) real steps, so efficiency is lost but computable language class is unchanged.

(Nondeterministic ⇒\Rightarrow deterministic.) A configuration has finitely many successor configurations, so the computation unfolds into a finitely-branching tree. A three-tape deterministic TM explores it breadth-first: tape 1 holds the current frontier, tape 2 generates each frontier node’s successors, tape 3 simulates one chosen node for its length. If any branch accepts, BFS reaches that accepting configuration in finite time; so the same language is recognised. (It recognises, not decides: breadth-first search does not halt on infinite rejecting branches, matching the nondeterministic semantics.) ■\blacksquare

7.3 Turing-Recognizable (Recursively Enumerable)

Section titled “7.3 Turing-Recognizable (Recursively Enumerable)”

A language is Turing-recognizable (RE) if some TM accepts it (may loop on non-members).

A language is decidable if some TM halts on all inputs (accepts members, rejects non-members).

Decidable⊊RE⊊All languages\text{Decidable} \subsetneq \text{RE} \subsetneq \text{All languages}

Any algorithmic procedure can be simulated by a Turing machine.

This is a thesis (not a theorem), it cannot be proven because “algorithmic procedure” is an informal notion.

  • TM defines the boundary of what is computable.
  • No more powerful computational model exists (in terms of computable functions).
  • Equivalent models: lambda calculus, μ\mu-recursive functions, Post systems, register machines.
LanguageDecidable?Algorithm
ADFA={(B,w):B accepts w}A_{\text{DFA}} = \{(B, w) : B \text{ accepts } w\}YesSimulate DFA on ww
ACFG={(G,w):G generates w}A_{\text{CFG}} = \{(G, w) : G \text{ generates } w\}YesCYK algorithm, O(n3∥G∥)O(n^3 \| G \| )
EDFA={A:L(A)=∅}E_{\text{DFA}} = \{A : L(A) = \emptyset\}YesCheck reachable accepting states
EQDFA={A,B:L(A)=L(B)}EQ_{\text{DFA}} = \{A, B : L(A) = L(B)\}YesCheck L(AΔB)‾\overline{L(A \Delta B)} for non-emptiness
ATM={(M,w):M accepts w}A_{\text{TM}} = \{(M, w) : M \text{ accepts } w\}NoDiagonalization proof

ATM={(M,w):M accepts w}A_{\text{TM}} = \{(M, w) : M \text{ accepts } w\} is undecidable.

Proof (diagonalization). Suppose HH decides ATMA_{\text{TM}}: H(⟨M,w⟩)H(\langle M, w \rangle) accepts exactly when MM accepts ww, and always halts. Define

D(M)={rejectif H(⟨M,⟨M⟩⟩) acceptsacceptif H(⟨M,⟨M⟩⟩) rejectsD(M) = \begin{cases} \text{reject} & \text{if } H(\langle M, \langle M \rangle \rangle) \text{ accepts} \\ \text{accept} & \text{if } H(\langle M, \langle M \rangle \rangle) \text{ rejects} \end{cases}

DD is a legitimate machine (it merely inverts HH‘s answer about a particular input). Now run DD on its own description: D(⟨D⟩)D(\langle D \rangle) accepts iff HH says DD rejects ⟨D⟩\langle D \rangle, iff D(⟨D⟩)D(\langle D \rangle) rejects. A machine accepts its input iff it rejects it; contradiction. So HH cannot exist, and ATMA_{\text{TM}} is undecidable. ■\blacksquare

To prove LL is undecidable, reduce a known undecidable language to LL.

Common undecidable problems:

ProblemReduction From
ETM={M:L(M)=∅}E_{\text{TM}} = \{M : L(M) = \emptyset\}ATMA_{\text{TM}}
REGTM={M:L(M) is regular}REG_{\text{TM}} = \{M : L(M) \text{ is regular}\}ATMA_{\text{TM}}
EQTM={M1,M2:L(M1)=L(M2)}EQ_{\text{TM}} = \{M_1, M_2 : L(M_1) = L(M_2)\}ETME_{\text{TM}}
PCP (Post Correspondence Problem)ATMA_{\text{TM}}
Hilbert’s 10th Problem (Diophantine equations)ATMA_{\text{TM}}

Theorem: Any non-trivial property of the language of a Turing machine is undecidable.

A property is non-trivial if it holds for some TMs and not for others.

Proof. Let PP be a decidable, non-trivial language property, and suppose DD decides it. Since PP is non-trivial, pick a machine TT with P(L(T))P(L(T)) true, and let T∅T_\emptyset be a machine recognising ∅\emptyset (which then satisfies PP falsely; if not, replace PP by its complement, still non-trivial, still decidable). WLOG also ensure ϵ∉L(T)\epsilon \notin L(T): if needed, build T′T' from TT that rejects ϵ\epsilon and behaves like TT otherwise, and argue with T′T' and a ϵ\epsilon-free variant of T∅T_\emptyset; the construction below is unchanged.

Given (M,w)(M, w), construct MwM_w: on input xx, first simulate MM on ww; if MM ever accepts, then simulate TT on xx and do whatever TT does; if MM rejects or loops, MwM_w loops.

  • If MM accepts ww: MwM_w never blocks, so L(Mw)=L(T)L(M_w) = L(T) and P(L(Mw))P(L(M_w)) holds.
  • If MM does not accept ww: MwM_w loops on every input, so L(Mw)=∅L(M_w) = \emptyset and P(L(Mw))P(L(M_w)) fails.

So P(L(Mw))  ⟺  (M,w)∈ATMP(L(M_w)) \iff (M, w) \in A_{\text{TM}}: a decider for PP yields a decider for the halting problem. But ATMA_{\text{TM}} is undecidable; contradiction. Hence no such DD exists. ■\blacksquare

Examples of undecidable properties (by Rice’s theorem):

  • Does MM accept any string?
  • Is L(M)L(M) finite?
  • Is L(M)L(M) regular?
  • Does L(M)=Σ∗L(M) = \Sigma^*?

Not covered by Rice’s theorem: Properties about the machine’s behavior (not its language), such as “does MM run for more than 100 steps on input ww?“

  1. Confusing NFA and DFA complexity. NFA simulation requires tracking multiple states simultaneously (O(2n)O(2^n) worst case for subset construction), but the NFA itself may be exponentially smaller than any equivalent DFA.

  2. Wrong string choice for pumping lemma proofs. The string must be long enough (≥p\geq p) and specifically chosen to make pumping impossible. A poor choice leads to failing the proof.

  3. Forgetting that CFLs are not closed under complement and intersection. Unlike regular languages, CFLs lose these closure properties. L‾\overline{L} of a CFL may not be context-free.

  4. Assuming decidability based on the existence of an algorithm. An algorithm that may not halt (e.g., simulating a TM) does not establish decidability. The TM must halt on all inputs.

  5. Misapplying Rice’s theorem. Rice’s theorem applies only to properties of the language recognized by a TM, not properties of the TM’s code or computation behavior.

  6. Confusing Turing-recognizable and decidable. Every decidable language is Turing-recognizable, but not vice versa. The halting problem is recognizable but not decidable.

  7. Assuming more tape heads make TMs more powerful. Multi-tape TMs are equivalent to single-tape TMs. No variant of the standard TM increases computational power (only efficiency).

Problem: Design a DFA over {0, 1} that accepts strings containing the substring “010”. Solution: States: q0 (start, scanning for first 0), q1 (saw 0, waiting for 1), q2 (saw 01, waiting for 0), q3 (accepting, saw 010). Transitions: q0 on 0 -> q1, q0 on 1 -> q0. q1 on 1 -> q2, q1 on 0 -> q1. q2 on 0 -> q3, q2 on 1 -> q0. q3 on 0 -> q3, q3 on 1 -> q3. The DFA has 4 states and transitions back to earlier states when partial matches are broken.

Example 2: Context-Free Grammar for a Language

Section titled “Example 2: Context-Free Grammar for a Language”

Problem: Write a CFG that generates the language L = {a^n b^n c^n : n >= 1}. Solution: S -> aBC. B -> aBB (this ensures more a’s push B’s onto the middle). C -> cD. D -> cDD (this ensures more c’s match). B -> b (terminal). D -> d (terminal). Wait — this generates a^n b^n c^m which is wrong. The language a^n b^n c^n is not context-free (proven by the pumping lemma for CFLs). No CFG exists for this language. This is a common exam trick question.

  • DFA and NFA recognize the same regular languages, convertible via subset construction.
  • Regular expressions are equivalent to finite automata (Thompson’s construction).
  • Pumping lemma for regular languages proves non-regularity by contradiction.
  • CFGs generate context-free languages, equivalent to PDAs.
  • Ambiguity means multiple parse trees; some CFLs are inherently ambiguous.
  • Pumping lemma for CFLs proves non-context-freeness (e.g., anbncna^n b^n c^n).
  • Turing machines are the most powerful model; equivalent to lambda calculus and recursive functions.
  • Church-Turing thesis: TMs capture all algorithmic computation.
  • Halting problem is undecidable (diagonalization). Rice’s theorem generalizes undecidability.

Automata theory studies abstract computing models. Finite automata recognize regular languages. Pushdown automata recognize context-free languages. Turing machines define the limits of computation. The Chomsky hierarchy classifies languages by automata complexity. Understanding these models reveals what can and cannot be computed, and informs compiler design, protocol verification, and formal specification.

TopicLink
CompilersView
Complexity TheoryView
Algorithm DesignView