Lecture 16 - Introduction To NP-Completeness
Lecture 16 - Introduction To NP-Completeness
Computer Science
Seth Pettie
Lecture 16
2
Today’s Agenda
Recap
Recap
* Example 1: f(x,y) = ¬x ∧ y
* Example 2: f(x,y,z) = (¬x ∨ y) ∧ (¬x ∨ z) ∧ (y ∨ z) ∧ (x ∨ ¬z)
So, to resolve P vs. NP, we “just” need to determine the status of SAT!
Either all of them are in P (so P=NP), or none are (so P ≠ NP).
6
Cook-Levin Outline
Proof outline:
* Let 𝐷$%& be an efficient decider for SAT.
* Let L ∈ NP, so L has an efficient verifier V.
* Goal: Build an efficient decider 𝐷' that uses 𝐷$%& and V.
* 𝐷' (𝑥):
* Efficiently construct a poly-size Boolean formula fV,x so that:
* 𝑥 ∈ 𝐿 ⟺ fV,x is satisfiable.
* Output 𝐷!"# (fV,x).
7
* Can show: fV,x can be computed using a 3-CNF formula (proof in the notes)
* Conclusion: 3SAT = {f | f is a satisfiable 3-CNF formula} is NP-Hard.
* Recall:
* We proved that 𝐿BARBER is undecidable by an ingenious ad-hoc
argument.
* We proved that many other languages (𝐿(%)& , 𝐿*+ , ...) are
undecidable via Turing reductions. E.g., 𝐿%,, ≤ - 𝐿(%)& shows that
𝐿(%)& is also undecidable.
* Now:
* We proved that SAT (and 3SAT) is “NP-hard” by an ingenious ad-hoc
argument.
* We will prove that other languages are NP-hard by a special
kind of reduction: polynomial-time mapping reduction.
99
𝐴 ≤! 𝐵
Σ∗ 𝑓 is poly-time Σ∗
computable
𝐴 𝐵
YES 𝑥 𝑓(𝑥) YES
NO 𝑦 𝑓(𝑦) NO
𝐍𝐏-Completeness
* We saw:
* SAT ∈ 𝐍𝐏
* SAT is 𝐍𝐏-Hard
* Thus, SAT is 𝐍𝐏-Complete.
12
12
𝐏 ⊂ 𝐍𝐏 𝐏 = 𝐍𝐏
𝐍𝐏-Hard 𝐍𝐏-Hard
𝐍𝐏-Complete =
𝐍𝐏 ∩ 𝐍𝐏-Hard
𝐍𝐏 𝐏 = 𝐍𝐏
= 𝐍𝐏-Complete
𝐏
13
13
Showing 𝐍𝐏-Completeness
Given a group of people, are there 𝑘 people that are mutual friends?
* Formally: Given a graph 𝐺 and integer 𝑘 ≥ 0, is there a
clique of size 𝑘 in 𝐺?
* CLIQUE = { 𝐺, 𝑘 ∣ 𝐺 is a graph with a clique of size 𝑘}
are friends
15
3SAT ≤! CLIQUE
Example
Goal: “translate” 3CNF formula 𝜑 into 𝐺" , 𝑘" such that:
• 𝜑 satisfiable ⇒ 𝐺" has 𝑘" -clique (clique: “yes”)
• 𝜑 not satisfiable ⇒ 𝐺" doesn’t have 𝑘" -clique (clique: “no”)
* 𝜑 = (𝑥 ∨ 𝑦 ∨ 𝑧) ∧ (¬𝑥 ∨ 𝑦 ∨ ¬𝑧) ∧ (𝑥 ∨ ¬𝑦 ∨ 𝑧)
* Q: How can we satisfy clause 𝑥 ∨ 𝑦 ∨ 𝑧 ?
* Q: What about clause ¬𝑥 ∨ 𝑦 ∨ ¬𝑧 ?
* Observation: We can satisfy a clause by picking any literal (e.g., 𝑥)
and making it true.
* We can’t use the underlying variable (e.g., 𝑥) to satisfy any
clause in which it appears differently (e.g., ¬𝑥)
* Idea: ...Maybe 𝑘) -clique ≡ a satisfying assignment?
18
Example
Goal: “translate” 3CNF formula 𝜑 into 𝐺" , 𝑘" such that:
• 𝜑 satisfiable ⇒ 𝐺" has 𝑘" -clique (clique: “yes”)
• 𝜑 not satisfiable ⇒ 𝐺" doesn’t have 𝑘" -clique (clique: “no”)
Observations:
𝑥 𝑥 1) Any clique can have at most one
vertex from a clause (𝑘! ≤ 3)
𝑦 ¬𝑦
𝑧 𝑧 2) A clique can have several x or ¬𝑥, but
not both
¬𝑥 𝑦 ¬𝑧
Will show: This graph has a clique of size 3 if and only if 𝜑 is satisfiable
19
Runtime Analysis
Build graph 𝐺! as follows:
• Make a vertex for each literal of each clause
• Add an edge between two literals in different
clauses only if they are “compatible” (refer to
different variables or they’re the same)
Vertex-Cover Problem
(Starbucks Problem)
street
street
corner
23
23
3SAT ≤! VERTEX−COVER
Goal: “translate” 𝜑 to 𝐺" , 𝑘" st:
• 𝜑 sat ⇒ 𝐺" has some 𝑘" -VC
• 𝜑 unsat ⇒ 𝐺" has no 𝑘" -VC
𝑧
𝑥 ¬𝑥 𝑥 ¬𝑦
3SAT ≤! VERTEX−COVER
Goal: “translate” 𝜑 to 𝐺" , 𝑘" st:
• 𝜑 sat ⇒ 𝐺" has some 𝑘" -VC
• 𝜑 unsat ⇒ 𝐺" has no 𝑘" -VC
* 𝜑 = (𝑥 ∨ 𝑦 ∨ 𝑧) ∧ (¬𝑥 ∨ 𝑦 ∨ ¬𝑧) ∧ (𝑥 ∨ ¬𝑦 ∨ 𝑧)
* Construction of 𝑮𝝋 : build variable gadgets and clause gadgets;
add edge 𝑢, 𝑣 if 𝑢 is in a variable gadget and 𝑣 is in a clause gadget
and 𝑢 and 𝑣 are labeled the same
* Set 𝒌𝝋 to 𝑛 + 2𝑚 (𝑛 – number of variables, 𝑚 – number of clauses)
variable 𝑥 ¬𝑥 𝑦 ¬𝑦 𝑧 ¬𝑧
gadgets
𝑧 ¬𝑧 𝑧
clause
gadgets 𝑥 𝑦 ¬𝑥 𝑦 𝑥 ¬𝑦
25
𝜙 satisfiable ⇒ 𝑛 + 2𝑚 -VC
* 𝜑 = (𝑥 ∨ 𝑦 ∨ 𝑧) ∧ (¬𝑥 ∨ 𝑦 ∨ ¬𝑧) ∧ (𝑥 ∨ ¬𝑦 ∨ 𝑧)
* 𝐴 = (1,0,0) is a satisfying assignment
* For every variable gadget: put 𝑥 in vertex-cover if 𝐴/ = 1 and ¬𝑥
otherwise
* Pick 2 vertices per clause gadget to cover other edges
variable 𝑥 ¬𝑥 𝑦 ¬𝑦 𝑧 ¬𝑧
gadgets
𝑧 ¬𝑧 𝑧
clause
gadgets 𝑥 𝑦 ¬𝑥 𝑦 𝑥 ¬𝑦
26
𝑛 + 2𝑚 -VC ⇒ 𝜙 satisfiable
* 𝜑 = (𝑥 ∨ 𝑦 ∨ 𝑧) ∧ (¬𝑥 ∨ 𝑦 ∨ ¬𝑧) ∧ (𝑥 ∨ ¬𝑦 ∨ 𝑧)
* Claim: In a (𝑛 + 2𝑚)-VC of 𝐺) , each variable/clause gadget has
exactly one/two vertices in cover.
* For each variable 𝑥, set 𝐴/ = 1 if 𝑥 is in cover; 0 o/w
* 𝐴 is a satisfying assignment!
variable 𝑥 ¬𝑥 𝑦 ¬𝑦 𝑧 ¬𝑧
gadgets
𝑧 ¬𝑧 𝑧
clause
gadgets 𝑥 𝑦 ¬𝑥 𝑦 𝑥 ¬𝑦