knowledge

TOC Summary

Compact reference of the definitions, theorems, and proof recipes of Theory of Computation: regular languages and the pumping lemma, Turing machines, decidability and recognizability, reductions, and the P, NP, and NP-completeness landscape.

Regular Languages

DFA. M=(Q,Σ,δ,q0,F)M=(Q,\Sigma,\delta,q_0,F) with total δ:Q×ΣQ\delta:Q\times\Sigma\to Q. Accepts ww iff δ^(q0,w)F\hat\delta(q_0,w)\in F. Accepts ϵ\epsilon iff q0Fq_0\in F.

NFA. Same tuple with δ:Q×(Σ{ϵ})2Q\delta:Q\times(\Sigma\cup\{\epsilon\})\to 2^Q: any number of next states, including none, plus ϵ\epsilon-moves. Accepts ww iff at least one path reading ww ends in FF.

Equivalence of models.

  • Every DFA is an NFA (the case with exactly one next state and no ϵ\epsilon-moves).
  • Every NFA has an equivalent DFA, by the subset construction: a DFA state is a set of NFA states. The DFA can be exponentially larger.
  • So DFAs and NFAs recognize exactly the same class, the regular languages.

Regular language. A language recognized by some DFA, equivalently some NFA.

  • Closed under: L\overline{L}, L1L2L_1\cup L_2, L1L2L_1\cap L_2, L1L2L_1\circ L_2 (concatenation), LL^* (Kleene star, L={w1wkk0, wiL}L^*=\{w_1\cdots w_k \mid k\ge 0,\ w_i\in L\}, which includes ϵ\epsilon).
  • L\overline{L}: keep the DFA, swap accepting and non-accepting states. L1L2L_1\cup L_2 and L1L2L_1\cap L_2: product DFA on Q1×Q2Q_1\times Q_2, accepting when one side (union) or both sides (intersection) accept. L1L2L_1\circ L_2: link two NFAs with ϵ\epsilon-moves, then determinize. LL^*: add a new accepting start state with an ϵ\epsilon-move to the old start, and ϵ\epsilon-moves from each accepting state back to it.

Regular languages to know.

  • \varnothing and Σ\Sigma^*: regular (a DFA with no accepting state; a DFA with all states accepting).
  • {ϵ}\{\epsilon\} and every finite language: regular.
  • Fixed substring, prefix, suffix, or position, e.g. strings ending in 11: regular.
  • Parity and divisibility, e.g. number of 11s divisible by 55: regular (counting modulo a fixed number).
  • Pattern shapes 010^*1^* and 01100^*110^*: regular.
  • Equal number of substrings 0101 and 1010: regular. The answer depends only on whether the first and last symbols are equal, which is two bits, not on the counts.

Non-regular languages to know. Each needs unbounded exact memory, which counting modulo a fixed number cannot provide.

  • {0n1nn0}\{0^n1^n \mid n\ge 0\}: must match two unbounded counts exactly.
  • {www{0,1}}\{ww \mid w\in\{0,1\}^*\}: must store the entire first half.
  • {0m1nm>n}\{0^m1^n \mid m>n\}.
  • Equal number of 00s and 11s.

Pumping lemma. If AA is regular, there is a length pp such that every sAs\in A with sp|s|\ge p splits as s=xyzs=xyz with:

  • y1|y|\ge 1,
  • xyp|xy|\le p,
  • xyizAxy^iz\in A for every i0i\ge 0.

This is a necessary condition only. It proves non-regularity by contradiction, never regularity.

Proving non-regularity (pumping).

  1. Assume LL is regular with pumping length pp.
  2. Pick one sLs\in L with sp|s|\ge p, written in terms of pp.
  3. Check every split s=xyzs=xyz with xyp|xy|\le p and y1|y|\ge 1. A good ss forces yy into a single block.
  4. Pick one ii (usually 00 or 22) for which xyizLxy^iz\notin L.

Proving non-regularity (closure). Assume LL is regular, then combine it with regular languages under closure (intersect with a regular filter, complement, union) to reach a known non-regular language. Example: C01={0n1n}C\cap 0^*1^* = \{0^n1^n\}, so equal 00s and 11s is non-regular.

Turing Machines and Computability

Turing machine (TM). M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M=(Q,\Sigma,\Gamma,\delta,q_0,q_{\text{accept}},q_{\text{reject}}): a finite control on a one-way-infinite tape, with ΣΓ\Sigma\subseteq\Gamma, blank ΓΣ\sqcup\in\Gamma\setminus\Sigma, and δ:(Q{qaccept,qreject})×ΓQ×Γ×{L,R}\delta:(Q\setminus\{q_{\text{accept}},q_{\text{reject}}\})\times\Gamma\to Q\times\Gamma\times\{L,R\} (read, write one cell, move one cell). On each input it accepts, rejects, or runs forever.

Recognizable. Some TM accepts every wLw\in L, and on wLw\notin L it rejects or runs forever. Not closed under complement: HALT\mathrm{HALT} is recognizable, but HALT\overline{\mathrm{HALT}} is not.

Decidable. Some TM halts on every input and accepts exactly LL. Closed under complement: run the decider and swap accept and reject.

Decidable languages. Every regular language; {0n1n}\{0^n1^n\}; equal 00s and 11s; {02n}\{0^{2^n}\} (unary powers of two).

Recognizable languages. LL is decidable iff both LL and L\overline{L} are recognizable (run both recognizers in alternation; one must accept).

Decidable problems about automata.

  • EDFA={DL(D)=}E_{\mathrm{DFA}}=\{\langle D\rangle \mid L(D)=\varnothing\}: decidable. L(D)=L(D)=\varnothing iff no accepting state is reachable from q0q_0, which is reachability on the state graph.
  • EQDFA={D,DL(D)=L(D)}EQ_{\mathrm{DFA}}=\{\langle D,D'\rangle \mid L(D)=L(D')\}: decidable. Build the DFA for the symmetric difference L(D)L(D)L(D)\oplus L(D') and test it for emptiness; the two are equal iff it is empty.

Church-Turing thesis. Anything computable by an algorithm is computable by a Turing machine. The same class of computable functions arises from multi-tape TMs, λ\lambda-calculus, and ordinary programming languages.

Encoding O\langle O\rangle. A finite string describing an object: a DFA, a graph, a TM, or a pair O1,O2\langle O_1,O_2\rangle. A decision problem is the set of encodings whose answer is yes.

Countability.

  • Countable: Σ\Sigma^*, all finite encodings, all DFAs, all Turing machines.
  • Uncountable: the set of all languages P(Σ)\mathcal{P}(\Sigma^*) (diagonal argument on characteristic sequences).
  • Consequence: there are more languages than Turing machines, so some languages are not recognizable.

Diagonalization. DIAG={MiMi does not accept Mi}\mathrm{DIAG}=\{\langle M_i\rangle \mid M_i \text{ does not accept } \langle M_i\rangle\} is undecidable. A decider for it would have to disagree with its own behavior on its own encoding.

Core undecidable problems.

  • ATM={M,wM accepts w}A_{\mathrm{TM}}=\{\langle M,w\rangle \mid M \text{ accepts } w\}: recognizable, undecidable.
  • HALT={M,wM halts on w}\mathrm{HALT}=\{\langle M,w\rangle \mid M \text{ halts on } w\}: recognizable, undecidable.
  • Difference on the no-instances: HALT\mathrm{HALT} says no only when MM loops; ATMA_{\mathrm{TM}} says no when MM rejects or loops.

Mapping reduction AmBA\le_m B. A total computable ff with wA    f(w)Bw\in A \iff f(w)\in B. It makes BB at least as hard as AA.

  • BB decidable A\Rightarrow A decidable. AA undecidable B\Rightarrow B undecidable.
  • BB recognizable A\Rightarrow A recognizable. AA unrecognizable B\Rightarrow B unrecognizable.

Proving undecidability by reduction.

  1. Take a known hard language: ATMA_{\mathrm{TM}} for undecidability, ATM\overline{A_{\mathrm{TM}}} for unrecognizability.
  2. Map each instance to a target instance by writing the new machine's code, without running it.
  3. Show ff is total computable and that wA    f(w)Bw\in A \iff f(w)\in B.

More undecidable and unrecognizable problems.

  • REGTM={NL(N) is regular}REG_{\mathrm{TM}}=\{\langle N\rangle \mid L(N) \text{ is regular}\}: undecidable, by ATMmREGTMA_{\mathrm{TM}}\le_m REG_{\mathrm{TM}}.
  • ATM\overline{A_{\mathrm{TM}}} and HALT\overline{\mathrm{HALT}}: not recognizable.
  • EQTM={M1,M2L(M1)=L(M2)}EQ_{\mathrm{TM}}=\{\langle M_1,M_2\rangle \mid L(M_1)=L(M_2)\}: not recognizable, by ATMmEQTM\overline{A_{\mathrm{TM}}}\le_m EQ_{\mathrm{TM}}, hence also undecidable.

Hierarchy. RegularDecidableRecognizableP(Σ)\text{Regular}\subsetneq\text{Decidable}\subsetneq\text{Recognizable}\subsetneq\mathcal{P}(\Sigma^*), every containment strict:

  • {0n1n}\{0^n1^n\}: decidable, not regular.
  • HALT\mathrm{HALT}: recognizable, not decidable.
  • HALT\overline{\mathrm{HALT}}: not recognizable.

Time Complexity: P and NP

Worst-case time. For a decider MM, t(n)t(n) is the maximum number of steps over all inputs of length nn. Defined for deciders only, since recognizers may loop.

Asymptotics.

  • f=O(g)f=O(g): f(n)Cg(n)f(n)\le C\,g(n) for some constant CC and all large nn.
  • f=o(g)f=o(g): f(n)/g(n)0f(n)/g(n)\to 0.

P. Languages decidable in polynomial time by a deterministic TM: P=k1TIME(nk)P=\bigcup_{k\ge 1}\mathrm{TIME}(n^k).

  • Every regular language is in PP (one constant-time step per input symbol).
  • Known in PP: sortedness of an array; ss-tt connectivity by BFS; graph connectivity.

Certificate and verifier. A verifier for LL reads a pair x,C\langle x,C\rangle, where CC is a proposed proof that xLx\in L. It is polynomial-time if valid certificates have length p(x)\le p(|x|) and the check runs in time polynomial in x|x|.

NP. Languages with a polynomial-time verifier.

  • xLx\in L iff some certificate is accepted; xLx\notin L iff every certificate is rejected.
  • Equivalent definition: languages decided by a polynomial-time nondeterministic TM, NP=k1NTIME(nk)NP=\bigcup_{k\ge 1}\mathrm{NTIME}(n^k). The certificate is the choices of one accepting branch.

P vs NP. PNPP\subseteq NP (a decider is a verifier that ignores the certificate). Whether P=NPP=NP is open.

Polynomial-time reduction APBA\le_P B. A total polynomial-time computable ff with wA    f(w)Bw\in A \iff f(w)\in B.

  • If APBA\le_P B and BPB\in P, then APA\in P.
  • Transitive: APBA\le_P B and BPCB\le_P C give APCA\le_P C.

NP-hard and NP-complete.

  • NP-hard: every LNPL\in NP reduces to it, LPHL\le_P H.
  • NP-complete: NP-hard and in NP.
  • If any NP-complete language is in PP, then P=NPP=NP.

Cook-Levin. SAT is NP-complete. So SATP    P=NP\mathrm{SAT}\in P \iff P=NP, and the same holds for every NP-complete language.

Proving LL NP-complete.

  1. Show LNPL\in NP with a polynomial-time verifier.
  2. Reduce a known NP-complete language to LL (direction: known problem L\to L, never LL \to known problem).
  3. By transitivity, every NP language then reduces to LL.
SATINDSET3SATVERTEX COVERCLIQUESET COVERSUBSET-SUMknown complete sources feed later complete targets by transitivity
SATINDSETCLIQUEVERTEX COVERSET COVERSUBSET-SUM3SATarrows transfer NP-hardnesswhen the target is in NP
Each arrow means a polynomial-time reduction from the source problem to the target problem.

NP-complete problems.

  • SAT: a CNF formula, an AND of clauses where each clause is an OR of literals, that has a satisfying assignment.
  • 3SAT: SAT restricted to formulas with at most 33 literals per clause.
  • INDSET: G,k\langle G,k\rangle where GG has kk vertices with no edge between any two.
  • CLIQUE: G,k\langle G,k\rangle where GG has kk vertices that are pairwise adjacent.
  • VERTEX COVER: G,k\langle G,k\rangle where GG has kk vertices that together touch every edge.
  • SET COVER: U,F,k\langle U,\mathcal{F},k\rangle where kk of the sets in F\mathcal{F} have union UU.
  • SUBSET-SUM: X,s\langle X,s\rangle where some sub-multiset of the positive integers XX sums to ss.

Graph isomorphism (GI). In NP, but not known to be NP-complete and not known to be in PP.

Pseudo-polynomial time. SUBSET-SUM has an O(mT)O(mT) dynamic program with T=ixiT=\sum_i x_i. This is polynomial in the integer values but exponential in the binary input length, so it does not place SUBSET-SUM in PP. NP-completeness assumes binary encoding.