knowledge

Theory of Computation: Lecture 8

Polynomial-time mapping reductions, NP-completeness, Cook-Levin, the 3SAT reduction, and the SAT-to-INDSET construction.

Polynomial-Time Reductions

NP membership says that yes-instances have short certificates that can be checked quickly. NP-completeness needs a second idea: translate one decision problem into another without losing the yes/no answer and without spending more than polynomial time.

Polynomial-time computable function. A function f:ΣΣf:\Sigma^*\to\Sigma^* is polynomial-time computable if some polynomial-time Turing machine halts on every input ww with exactly f(w)f(w) on its tape.

The function must be total. It must produce an output for every input, even when the input is a no-instance.

Polynomial-time mapping reduction. A language AA is polynomial-time mapping reducible to a language BB, written APBA\le_P B, if there is a polynomial-time computable function f:ΣΣf:\Sigma^*\to\Sigma^* such that, for every string ww,

wAf(w)B.w\in A \quad\Longleftrightarrow\quad f(w)\in B.
  • Computability. The instance f(w)f(w) can be constructed in polynomial time.
  • Correctness. The translation preserves membership exactly.
  • Surjectivity. Not required. Some instances of BB may never be produced by ff.

The direction APBA\le_P B means: a fast solver for BB would give a fast solver for AA. So BB is at least as hard as AA.

Theorem. If APBA\le_P B and BPB\in P, then APA\in P.

Proof. Let ff be a polynomial-time reduction from AA to BB, and let MBM_B be a polynomial-time decider for BB. Build a decider NN for AA:

  1. On input ww, compute f(w)f(w).
  2. Run MBM_B on f(w)f(w).
  3. Output whatever MBM_B outputs.

The machine NN decides AA because

N accepts wMB accepts f(w)f(w)BwA.N\text{ accepts }w \quad\Longleftrightarrow\quad M_B\text{ accepts }f(w) \quad\Longleftrightarrow\quad f(w)\in B \quad\Longleftrightarrow\quad w\in A.

Cost rule. If ff runs in O(nq)O(n^q) time and MBM_B runs in O(np)O(n^p) time, then f(w)=O(wq)|f(w)|=O(|w|^q) because the reduction cannot write more symbols than its running time allows. The composed decider runs in

O(wq)+O(f(w)p)=O(wq+wpq)=O(wpq)O(|w|^q)+O(|f(w)|^p) = O(|w|^q+|w|^{pq}) = O(|w|^{pq})

for fixed constants p,q1p,q\ge 1.

Corollary. If APBA\le_P B and APA\notin P, then BPB\notin P.

This is a hardness transfer. For NP problems, however, we usually do not know that a natural language is outside PP. NP-completeness replaces that missing knowledge with reductions from all of NPNP.

Transitivity of polynomial-time reductions. If APBA\le_P B and BPCB\le_P C, then APCA\le_P C.

If fABf_{AB} runs in O(np)O(n^p) time and fBCf_{BC} runs in O(nq)O(n^q) time, the composed map wfBC(fAB(w))w\mapsto f_{BC}(f_{AB}(w)) is polynomial-time computable. Correctness follows by chaining the two equivalences:

wAfAB(w)BfBC(fAB(w))C.w\in A \quad\Longleftrightarrow\quad f_{AB}(w)\in B \quad\Longleftrightarrow\quad f_{BC}(f_{AB}(w))\in C.

NP-Complete Languages

NP-hard language. A language HH is NP-hard if every language in NPNP polynomial-time reduces to it:

LNP,LPH.\forall L\in NP,\quad L\le_P H.

NP-complete language. A language HH is NP-complete if it is both in NPNP and NP-hard.

  • Membership. HNPH\in NP, so yes-instances of HH have short certificates.
  • Hardness. Every problem in NPNP can be translated to HH in polynomial time.

If any NP-complete language has a polynomial-time decider, then P=NPP=NP: for every LNPL\in NP, use LPHL\le_P H and the theorem above to get LPL\in P.

Cook-Levin theorem. SAT\mathrm{SAT} is NP-complete.

Thus SAT\mathrm{SAT} is the first complete problem: it is in NPNP, and every language in NPNP reduces to it in polynomial time.

Recipe: proving that LL is NP-complete.

  1. NP membership. Give a polynomial-time verifier for LL.
  2. NP-hardness. Reduce a known NP-complete language to LL.
  3. Conclusion. Since the known complete problem represents all of NPNP, transitivity gives every ANPA\in NP a reduction to LL.

At the start, the known NP-complete language is SAT\mathrm{SAT}. Later, any already proven NP-complete language may be used.

The 3SAT Reduction

kkSAT. The language of satisfiable CNF formulas in which every clause contains at most kk literals.

With this convention, 33SAT allows clauses of size 11, 22, or 33.

Theorem. 3SAT3\mathrm{SAT} is NP-complete.

Membership in NPNP is inherited from SAT\mathrm{SAT}: a certificate is a truth assignment, and the verifier checks every clause.

For hardness, reduce SAT\mathrm{SAT} to 3SAT3\mathrm{SAT}. Let KK be a clause with more than three literals:

K=(123m),m>3.K=(\ell_1\vee \ell_2\vee \ell_3\vee\cdots\vee \ell_m), \qquad m>3.

Introduce a fresh variable zz and replace KK by two clauses:

K1=(12z),K2=(¬z3m).K_1=(\ell_1\vee \ell_2\vee z), \qquad K_2=(\neg z\vee \ell_3\vee\cdots\vee \ell_m).

This preserves satisfiability.

If KK is satisfiable and one of 1,2\ell_1,\ell_2 is true, set z=falsez=\mathrm{false}. Then K1K_1 is true because of the original true literal, and K2K_2 is true because of ¬z\neg z. If a true literal appears only among 3,,m\ell_3,\ldots,\ell_m, set z=truez=\mathrm{true}.

Conversely, if all original literals 1,,m\ell_1,\ldots,\ell_m are false, then K1K_1 forces z=truez=\mathrm{true} while K2K_2 forces z=falsez=\mathrm{false}, impossible. So any satisfying assignment for K1K2K_1\wedge K_2 makes at least one original literal true.

Repeat this replacement until every clause has at most three literals. Each step shortens one long clause by one literal, introduces one fresh variable, and increases the formula size only linearly. Therefore the whole transformation is polynomial time, and the resulting formula is satisfiable exactly when the original formula is satisfiable.

The same idea does not give a SAT-to-2SAT reduction: binary clauses cannot carry the remaining tail of a long disjunction in the same satisfiability-preserving way.

INDSET Is NP-Complete

Independent set language. The language

INDSET={G,kG has an independent set of size k}.\mathrm{INDSET} = \{\langle G,k\rangle\mid G\text{ has an independent set of size }k\}.

Membership in NPNP is immediate: a certificate is a set SV(G)S\subseteq V(G), and the verifier checks that S=k|S|=k and that no pair of vertices in SS is connected by an edge.

Theorem. INDSET\mathrm{INDSET} is NP-complete.

It remains to prove NP-hardness by showing SATPINDSET\mathrm{SAT}\le_P\mathrm{INDSET}.

Reduction from SAT to INDSET. Given a CNF formula φ\varphi with clauses K1,,KmK_1,\ldots,K_m, build a graph GG as follows:

  1. Create one vertex for each literal occurrence in each clause.
  2. Add edges between every pair of vertices from the same clause.
  3. Add edges between every pair of conflicting literals, such as xix_i and ¬xi\neg x_i.
  4. Output G,m\langle G,m\rangle.

Each clause becomes a clique, so an independent set can select at most one literal per clause. Conflict edges prevent it from selecting inconsistent literals.

For example, for

φ=(¬x1)(x1¬x2)(x1x2¬x3)(x1x2x3¬x4),\varphi = (\neg x_1) \wedge (x_1\vee \neg x_2) \wedge (x_1\vee x_2\vee \neg x_3) \wedge (x_1\vee x_2\vee x_3\vee \neg x_4),

the selected vertices correspond to the satisfying assignment x1=x2=x3=x4=falsex_1=x_2=x_3=x_4=\mathrm{false}.

example constructionK3K1K2K4¬x1x1¬x2x1x2¬x3x1x2x3¬x4solid edges: clause cliquesdashed edges: conflicting literalsoutlined nodes: chosen independent set
example constructionK1K2K3K4¬x1x1¬x2x1x2¬x3x1x2x3¬x4solid: clause cliquesdashed: conflictsoutlined: chosen set
SAT reduces to INDSET by turning clauses into cliques and contradictions into conflict edges.

Correctness: satisfiable formula gives independent set. Suppose φ\varphi has a satisfying assignment. In each clause, choose one literal that is true. The chosen vertices form an independent set of size mm: there is one chosen vertex per clause, so no same-clause edge is used, and two true literals under one assignment cannot be conflicting.

Correctness: independent set gives satisfying assignment. Suppose GG has an independent set SS of size mm. Since each clause group is a clique, SS contains at most one vertex from each clause. There are mm clauses and S=m|S|=m, so it contains exactly one vertex from every clause. Since SS has no conflict edge, the selected literals are mutually consistent. Set each selected literal to true and assign the remaining variables arbitrarily. Every clause has a selected true literal, so φ\varphi is satisfiable.

The graph has one vertex per literal occurrence and at most quadratically many edges in the formula size, so the construction is polynomial time. Therefore SATPINDSET\mathrm{SAT}\le_P\mathrm{INDSET}, and since INDSETNP\mathrm{INDSET}\in NP, the language is NP-complete.