Section 6 · Revision

Theory of Computation formula sheet

State counts, conversions, normal forms, closure tables and decidability facts for regular, context-free and Turing-recognisable languages on one page.

Full notes Section test

Regular expressions and finite automata

Conversions and state bounds

From To States
NFA with nn states DFA (subset construction) at most 2n2^n, including ∅\emptyset
ϵ\epsilon-NFA with nn states NFA without ϵ\epsilon nn (same states)
Regex of length nn ϵ\epsilon-NFA (Thompson) O(n)O(n)
DFAs with mm and nn states DFA for ∩,∪,−,⊕\cap, \cup, -, \oplus (product) at most mnmn
Complete DFA with nn states DFA for complement nn (swap accepting and non-accepting)
DFA with nn states DFA for reversal up to 2n2^n
Mealy with nn states, output alphabet Δ\Delta Moore at most n∣Δ∣n \lvert \Delta \rvert (plus 1 for the start)
Moore with nn states Mealy nn
  • Swapping final states complements only a complete DFA, never an NFA.
  • Moore output for input of length nn has length n+1n + 1; Mealy gives nn.
  • Labelled DFAs with nn states, kk symbols, fixed start: nnk⋅2nn^{nk} \cdot 2^n.

Minimal complete DFA sizes (pattern ss with ∣s∣=k\lvert s \rvert = k, alphabet {a,b}\{a,b\}, ss like abab…abab\dots with no self-overlap issues)

Language States Dead state?
Length exactly kk k+2k + 2 yes
Length ≤k\le k k+2k + 2 yes
Length ≥k\ge k k+1k + 1 no
kk-th symbol from the left is fixed k+2k + 2 yes
kk-th symbol from the right is fixed 2k2^k no
Starts with ss k+2k + 2 yes
Ends with ss k+1k + 1 no
Contains ss k+1k + 1 no
Does not contain ss k+1k + 1 yes (counted)
na(w) mod m=rn_a(w) \bmod m = r mm no
Length divisible by mm or by nn (m,nm, n coprime) mnmn no
Binary, MSB first, value divisible by n=2jmn = 2^j m (mm odd) m+jm + j no
Binary, LSB first, value divisible by odd mm mm no
  • Partial DFA = complete DFA minus the dead state. Read whether the question counts it.
  • Product states can merge after minimisation. Example: na≡0(mod3)n_a \equiv 0 \pmod 3 and ends in bb needs 4 states, not 6.
  • Myhill-Nerode: number of classes = states of the minimal complete DFA. Infinite index means not regular.
  • Minimisation: drop unreachable states first, then merge equivalent states (Moore table filling).

Regular expression identities

  • (a+b)∗=(a∗b∗)∗=(a∗b)∗a∗=a∗(ba∗)∗(a + b)^* = (a^* b^*)^* = (a^* b)^* a^* = a^*(b a^*)^*

  • Shift rule: (xy)∗x=x(yx)∗(xy)^* x = x (yx)^*

  • (r∗)∗=r∗(r^*)^* = r^*, r∗r∗=r∗r^* r^* = r^*, ϵ+rr∗=r∗\epsilon + r r^* = r^*, ∅∗=ϵ\emptyset^* = \epsilon, r∅=∅r \emptyset = \emptyset

  • (a+b)∗≠a∗+b∗(a + b)^* \ne a^* + b^* (the right side misses abab)

  • Arden: R=Q+RPR = Q + RP gives R=QP∗R = QP^*; R=Q+PRR = Q + PR gives R=P∗QR = P^* Q (unique if ϵ∉L(P)\epsilon \notin L(P)).

  • Binary strings of length nn with no 1111: Fn+2F_{n+2} (2, 3, 5, 8, 13, 21 for n=1..6n = 1..6).

  • ϵ\epsilon-closure of qq always contains qq.

Context-free grammars and PDAs

Normal forms and counts (string length n≥1n \ge 1)

Quantity Value
CNF derivation steps 2n−12n - 1
CNF parse tree: variable nodes / all nodes 2n−12n - 1 / 3n−13n - 1
CNF parse tree height (edges) min ⌈log⁡2n⌉+1\lceil \log_2 n \rceil + 1, max nn
GNF derivation steps nn
CYK table cells n(n+1)/2n(n+1)/2
CYK time O(n3∣G∣)O(n^3 \lvert G \rvert)
Parse trees of a∘a∘…a \circ a \circ \dots with kk operators in E→E∘E∣aE \to E \circ E \mid a Catalan CkC_k: 1, 1, 2, 5, 14, 42, 132
Strings of length 2n2n from S→aSbS∣bSaS∣ϵS \to aSbS \mid bSaS \mid \epsilon (2nn)\binom{2n}{n}
Balanced strings (S→aSb∣SS∣ϵS \to aSb \mid SS \mid \epsilon) of length 2n2n CnC_n
  • Simplification order: remove ϵ\epsilon-productions, then unit productions, then useless symbols (non-generating first, then unreachable).
  • Palindromes of length nn over {a,b}\{a,b\}: 2⌈n/2⌉2^{\lceil n/2 \rceil}.

PDA facts

Model Accepts
NPDA, final state CFL
NPDA, empty stack CFL (same class)
DPDA, final state DCFL
DPDA, empty stack DCFLs with the prefix property
PDA with bounded stack regular
PDA with 2 stacks / queue automaton RE (same as TM)

DCFL or not

Deterministic CFL CFL, not deterministic
{wcwR}\{wcw^R\} {wwR}\{ww^R\}
{anbn}\{a^n b^n\}, {anb2n}\{a^n b^{2n}\} {anbn}∪{anb2n}\{a^n b^n\} \cup \{a^n b^{2n}\}
{anbm:n≠m}\{a^n b^m : n \ne m\} {aibjck:i=j or j=k}\{a^i b^j c^k : i = j \text{ or } j = k\} (inherently ambiguous)
every regular language {w:w≠wR}\{w : w \ne w^R\}
  • Ambiguity is a property of a grammar; inherent ambiguity is a property of a language. Every DCFL and every regular language has an unambiguous grammar.
  • Dangling else: S→aS∣aSbS∣ϵS \to aS \mid aSbS \mid \epsilon is ambiguous (aabaab has 2 trees).

Pumping lemma and closure properties

  • Regular, s=xyzs = xyz: ∣xy∣≤p\lvert xy \rvert \le p, ∣y∣≥1\lvert y \rvert \ge 1, xyiz∈Lxy^iz \in L for all i≥0i \ge 0.

  • CFL, s=uvxyzs = uvxyz: ∣vxy∣≤p\lvert vxy \rvert \le p, ∣vy∣≥1\lvert vy \rvert \ge 1, uvixyiz∈Luv^ixy^iz \in L for all i≥0i \ge 0.

  • The lemma only proves non-membership. Passing it proves nothing.

  • nn-state DFA: LL non-empty iff it accepts a string of length <n< n; LL infinite iff it accepts one of length in [n,2n−1][n, 2n - 1].

  • Unary CFLs are regular. So {an2}\{a^{n^2}\}, {a2n}\{a^{2^n}\}, {ap:p prime}\{a^p : p \text{ prime}\} are not CFL.

  • For an2a^{n^2}: pumping up gives length strictly between p2p^2 and (p+1)2(p+1)^2.

If you see X, think Y

Pattern Class
anbna^n b^n, wwRww^R, equal counts of two symbols CFL, not regular
anbncna^n b^n c^n, wwww, anbmcndma^n b^m c^n d^m not CFL
wxwRwxw^R with w,xw, x non-empty regular (first symbol = last, length ≥3\ge 3)
{ww}‾\overline{\{ww\}}, {anbncn}‾\overline{\{a^n b^n c^n\}} CFL
Equal counts of abab and baba regular (w=ϵw = \epsilon or first symbol = last)
Bounded counter (n≤1000n \le 1000) finite, so regular

Closure table (Y closed, N not closed)

Operation Reg DCFL CFL CSL Rec RE
Union Y N Y Y Y Y
Intersection Y N N Y Y Y
Intersection with regular Y Y Y Y Y Y
Complement Y Y N Y Y N
Difference Y N N Y Y N
Concatenation Y N Y Y Y Y
Kleene star Y N Y Y Y Y
Reversal Y N Y Y Y Y
Homomorphism Y N Y N N Y
ϵ\epsilon-free homomorphism Y N Y Y Y Y
Inverse homomorphism Y Y Y Y Y Y
Right quotient with regular Y Y Y N N Y
  • Regular languages are closed under quotient with any language, and under prefix, suffix, half, min⁡\min, {w:ww∈L}\{w : ww \in L\}.
  • L1∪L2L_1 \cup L_2 regular does not make L1,L2L_1, L_2 regular. A subset of a regular language need not be regular. An infinite union of regular languages need not be regular. L∗L^* regular does not make LL regular ({ap:p prime}∗\{a^p : p \text{ prime}\}^* is regular).
  • CFL ∩\cap regular is CFL: use it to expose a non-CFL core, e.g. L∩a∗b∗c∗L \cap a^*b^*c^*.

Turing machines and undecidability

Hierarchy

Type Grammar Machine Language class
3 right-linear DFA / NFA regular
2 context-free NPDA CFL
1 context-sensitive LBA CSL (all recursive)
0 unrestricted TM RE

Regular ⊂\subset DCFL ⊂\subset CFL ⊂\subset CSL ⊂\subset Recursive ⊂\subset RE ⊂\subset all languages.

  • Same power as a TM: multi-tape (O(t2)O(t^2) simulation), nondeterministic (exponential simulation), two-way infinite tape, multi-head, 2-stack PDA, 2-counter machine, queue automaton.
  • Weaker: single-stack PDA, LBA, read-only TM (regular).

Decidability (D decidable, U undecidable)

Problem DFA / regex CFG CSG TM
Membership w∈Lw \in L D D D U
Emptiness D D U U
Finiteness D D U U
L=Σ∗L = \Sigma^* D U U U
Equivalence D U U U
Containment D U U U
Intersection empty (two of the same type) D U U U
Ambiguity U
Is LL regular? D U U U
  • DPDA equivalence is decidable. CFG ∩\cap DFA emptiness is decidable.
  • PCP: undecidable for alphabets of size ≥2\ge 2, decidable for a one-letter alphabet or when the solution length is bounded.

Standard sets

Set RE co-RE
ATMA_{TM}, HALTHALT, {M:L(M)≠∅}\{M : L(M) \ne \emptyset\}, "accepts ϵ\epsilon" Y N
ATM‾\overline{A_{TM}}, HALT‾\overline{HALT}, ETM={M:L(M)=∅}E_{TM} = \{M : L(M) = \emptyset\} N Y
TOTALTOTAL, EQTMEQ_{TM}, FINTMFIN_{TM}, REGTMREG_{TM}, {M:L(M)=Σ∗}\{M : L(M) = \Sigma^*\} N N
  • LL and L‾\overline{L} both RE ⇒\Rightarrow LL recursive. LL RE but not recursive ⇒\Rightarrow L‾\overline{L} not RE.
  • RE ∪\cup recursive is RE; it may or may not be recursive.

Rice's theorem

  • Every non-trivial property of L(M)L(M) is undecidable.
  • Applies only to properties of the language. Does not apply to: number of states, "halts within kk steps", "makes more than kk moves", "ever moves left on blank input". Those are about the machine; many are decidable.
  • Trivial property (true for all RE languages or for none): decidable.
  • If some LL has the property but a superset of LL does not (not monotone), the property is not even RE.

Reductions (A≤mBA \le_m B)

  • BB decidable ⇒\Rightarrow AA decidable; BB RE ⇒\Rightarrow AA RE.

  • AA undecidable ⇒\Rightarrow BB undecidable; AA not RE ⇒\Rightarrow BB not RE.

  • Always A‾≤mB‾\overline{A} \le_m \overline{B}.

  • Standard trick: from ⟨M,w⟩\langle M, w \rangle build M′M' that ignores its input and runs MM on ww. Then L(M′)=Σ∗L(M') = \Sigma^* or ∅\emptyset. This gives ATM≤m{M:L(M)≠∅}A_{TM} \le_m \{M : L(M) \ne \emptyset\} and ATM‾≤mETM\overline{A_{TM}} \le_m E_{TM}.

Countability

  • Countable: Σ∗\Sigma^*, TMs, regexes, RE languages, finite subsets of N\mathbb{N}, Q\mathbb{Q}.

  • Uncountable: 2Σ∗2^{\Sigma^*} (all languages), R\mathbb{R}, functions N→{0,1}\mathbb{N} \to \{0,1\}, infinite subsets of N\mathbb{N}.

  • Countably many TMs, uncountably many languages: non-RE languages exist.