0% found this document useful (0 votes)
19 views

Lecture 16 - Introduction To NP-Completeness

NP Conpleteness

Uploaded by

bana milk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lecture 16 - Introduction To NP-Completeness

NP Conpleteness

Uploaded by

bana milk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

EECS 376: Foundations of

Computer Science
Seth Pettie
Lecture 16
2

Today’s Agenda

* Recap: Cook-Levin Theorem and Satisfiability


* 3-CNF Satisfiability
* Clique
* Vertex-Cover
3

Recap

* 𝐏 is the class of efficiently decidable languages


* 𝐍𝐏 is the class of efficiently verifiable languages

* 𝐿 ∈ NP if there exists a polynomial time in 𝑥 algorithm 𝑉(𝑥, 𝑐) such


that:
* 𝑥 ∈ 𝐿 ⟹ 𝑉(𝑥, 𝑐) accepts for at least one 𝑐
* 𝑥 ∉ 𝐿 ⟹ 𝑉 𝑥, 𝑐 rejects for every 𝑐

Intuitively: If I somehow “knew” a valid c, I could convince


anyone (who can do poly-time computations) that x ∈ L.
4

Recap

* Satisfiability problem (SAT): Given a Boolean formula, is there some


satisfying assignment (that makes it true)
* 𝐿!"# = Φ Φ is satisfiable (also just denoted SAT)

* Example 1: f(x,y) = ¬x ∧ y
* Example 2: f(x,y,z) = (¬x ∨ y) ∧ (¬x ∨ z) ∧ (y ∨ z) ∧ (x ∨ ¬z)

* Informal Definition: L is called NP-Hard if L ∈ P implies that NP = P.


* In other words: A poly-time algorithm for L can be converted to
yield poly-time algorithms for all efficiently verifiable languages!
That is, for every language in NP.
5
Two Amazing Works
(Given Turing Awards)

Cook-Levin (1971): SAT is “NP-hard.” In particular:


If SAT is in P, then all of NP is in P, i.e., P=NP.
(Also: if SAT is not in P, then P≠NP.)

So, to resolve P vs. NP, we “just” need to determine the status of SAT!

Karp (1972): TSP, Ham-Cycle, Subset Sum, …


all of these are “equivalent” to SAT.

Either all of them are in P (so P=NP), or none are (so P ≠ NP).
6

Cook-Levin Outline

Theorem [Cook-Levin]: If SAT ∈ P, then NP ⊆ P.

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

3-CNF Satisfiability Problem

* SAT formulas can be complicated.


* Question: Can we make them all simpler?

* Definition: A clause is a disjunction (OR) of 3 literals (x ∨ ¬y ∨ z)


Definition: A 3-CNF formula (CNF = conjunctive normal form) is a
conjunction (AND) of clauses E.g., (x ∨ ¬y ∨ z) ∧ (¬x ∨ z ∨ w) ∧ …

* 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.

Q: To prove some L is NP-Hard, must we redo Cook-Levin?


88

Reductions, Then and Now

* 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

Poly-Time Mapping Reductions

* Theorem [Cook-Levin]: For any 𝐿 ∈ 𝐍𝐏, there is a poly-time


algorithm 𝑓 such that 𝑥 ∈ 𝐿 ⟺ 𝑓(𝑥) ∈ SAT.
* Definition: Language 𝐴 is polynomial-time mapping reducible
to language 𝐵, written 𝐴 ≤! 𝐵, if there is a poly-time
algorithm 𝑓 such that:
𝑥 ∈ 𝐴 ⟺ 𝑓(𝑥) ∈ 𝐵.
* Recall: If 𝐴 ≤ " 𝐵 and 𝐵 is decidable then so is 𝐴.
* Theorem: If 𝐴 ≤! 𝐵 and 𝐵 ∈ 𝐏 then 𝐴 ∈ 𝐏.
* Proof: Construct efficient decider for 𝐴: given 𝑥,
1. Compute 𝑓(𝑥)
2. Run 𝐵-decider on 𝑓(𝑥).
10
10

𝐴 ≤! 𝐵

Σ∗ 𝑓 is poly-time Σ∗
computable
𝐴 𝐵
YES 𝑥 𝑓(𝑥) YES

NO 𝑦 𝑓(𝑦) NO

* Remark: 𝑓 need not be injective nor surjective!


1111

𝐍𝐏-Completeness

* Theorem [Cook-Levin]: For every 𝐴 ∈ 𝐍𝐏, 𝐴 ≤! SAT.


* Definition: Language 𝐵 is 𝐍𝐏-Hard if 𝐴 ≤! 𝐵 for all 𝐴 ∈ 𝐍𝐏.
* Definition: Language 𝐵 is 𝐍𝐏-Complete if:
1. 𝐵 ∈ 𝐍𝐏
2. 𝐵 is 𝐍𝐏-Hard

* We saw:
* SAT ∈ 𝐍𝐏
* SAT is 𝐍𝐏-Hard
* Thus, SAT is 𝐍𝐏-Complete.
12
12

𝐍𝐏-Hard and -Complete

𝐏 ⊂ 𝐍𝐏 𝐏 = 𝐍𝐏

𝐍𝐏-Hard 𝐍𝐏-Hard

𝐍𝐏-Complete =
𝐍𝐏 ∩ 𝐍𝐏-Hard

𝐍𝐏 𝐏 = 𝐍𝐏
= 𝐍𝐏-Complete
𝐏
13
13

Showing 𝐍𝐏-Completeness

* To show that a language 𝐵 is 𝐍𝐏-Complete:


1. Show that 𝐵 ∈ 𝐍𝐏.
* Write a verifier 𝑉 for 𝐵, show that it is correct and efficient.
2. Show that 𝐴 ≤$ 𝐵 for some known 𝐍𝐏-Complete 𝐴.
* Write a procedure 𝑓 mapping instances of 𝐴 to instances of 𝐵,
show that it is efficient and correct:
* 𝑥 ∈ 𝐴 ⟺ 𝑓(𝑥) ∈ 𝐵 (both directions!)
* Does NOT require converting instances of 𝐵 to instances of 𝐴!
Typically, many valid instances of 𝐵 will not be output by 𝑓.
(I.e., 𝑓 is not surjective.)
14

Example: Clique Problem

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

Clique seems hard

* Verifying is easy: We know that CLIQUE ∈ 𝐍𝐏 (see last lecture)


* Deciding seems hard: The naive algorithm for the clique problem
𝑛
(try all subsets of size 𝑘) runs in Ω time, where 𝑛 = # vertices
𝑘
* If 𝑘 = Θ(𝑛), then runtime is exponential 2%(') in size of input

But maybe there is a smarter algorithm out there?

* Idea: We’ll show that given a (hypothetical) efficient program


clique for CLIQUE, we could build an efficient program for 3SAT

* Formally: We will show that 3SAT ≤$ CLIQUE


* Conclusion: Since 3SAT is NP-Complete and CLIQUE ∈ 𝐍𝐏,
then CLIQUE must also be NP-Complete
16

3SAT ≤! CLIQUE

* Need to “translate” a 3SAT formula 𝜑 into 𝐺) , 𝑘) such that:


* 𝜑 is satisfiable ⇒ 𝐺) has 𝑘) -clique (clique: “yes”)
* 𝜑 is not satisfiable ⇒ 𝐺) doesn’t have 𝑘) -clique (clique: “no”)

* Proof outline for showing 3SAT ≤$ CLIQUE:


* Define an 𝑓 that converts a formula ϕ to some 𝐺" , 𝑘"
* Show that 𝑓 is correct: 𝜙 ∈ 3SAT ⟺ 𝐺" , 𝑘" ∈ CLIQUE.
* Show that 𝑓 is efficient.
17

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”)

* 𝜑 = (𝑥 ∨ 𝑦 ∨ 𝑧) ∧ (¬𝑥 ∨ 𝑦 ∨ ¬𝑧) ∧ (𝑥 ∨ ¬𝑦 ∨ 𝑧) with 3 clauses


* Idea for 𝐺" : make each literal a vertex; add an edge between two literals in
different clauses only if they’re “compatible”
(refer to different variables or they’re the same)

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

Correctness Analysis (1/2)


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)
¬𝑥 𝑦 ¬𝑧
* Suppose that 𝜑 = 𝐶* ∧ 𝐶+ ∧ ⋯ ∧ 𝐶, has 𝑚 clauses

* Claim: 𝜑 is satisfiable ⇒ 𝐺) has an 𝑚-clique (i.e. use 𝑘) = 𝑚).

* Consider any satisfying assignment 𝐴 of 𝜑


* Since 𝜑 is satisfied by 𝐴, for 1 ≤ 𝑖 ≤ 𝑚, each 𝐶- (e.g., 𝑥 ∨ 𝑦 ∨ 𝑧) has a
literal ℓ- (pick any if several choices) that evaluates to true under 𝐴

* We claim that {ℓ*, ℓ+, … , ℓ, } is an 𝑚-clique in 𝐺)


* Consider any two literals ℓ$ and ℓ% , 𝑖 ≠ 𝑗
* If ℓ$ = ℓ% , then there’s an edge between them in 𝐺& .
* Otherwise, ℓ$ and ℓ% must refer to different variables! (why?)
* Hence, they also have an edge between them.
20

Correctness Analysis (2/2)


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)
¬𝑥 𝑦 ¬𝑧

* Suppose that 𝜑 = 𝐶' ∧ 𝐶( ∧ ⋯ ∧ 𝐶) has 𝑚 clauses

* Claim: 𝜑 is not satisfiable ⇒ 𝐺" doesn’t have an 𝑚-clique.


* Equivalently: 𝐺" has an 𝑚-clique ⇒ 𝜑 is satisfiable

* Suppose that {ℓ' , ℓ( , … , ℓ) } is an 𝑚-clique in 𝐺" (one literal per clause)


* Define an assignment 𝐴 of 𝜑 by taking each literal ℓ* and setting the underlying
variable so that ℓ* is true (if any variables are unset at the end, set them arbitrarily)

* By construction of 𝐺" , since ℓ' , ℓ( , … , ℓ) is a clique in 𝐺" , there are


no conflicts in setting the variables this way
* Since 𝐴 satisfies each clause of 𝜑, it satisfies 𝜑!
21

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)

* Claim: We can build graph 𝐺) efficiently (poly-time in size of 𝜑)


* Suppose 𝜑 has 𝑚 clauses. 𝜑 = 𝑂(𝑚)
* There are 3𝑚 literals in 𝜑
* The graph 𝐺) has 3𝑚 vertices and 𝑂 3𝑚 + = 𝑂(𝑚+) edges
* Takes 𝑂(𝑚+) time to build and 𝐺) , 𝑘) = 𝑂 𝑚+

* Conclusion: Given a hypothetical efficient program clique( 𝐺) , 𝑘) ),


we can build an efficient program for 3SAT,
i.e. 3SAT ≤$ CLIQUE, so CLIQUE is NP-Complete
22

Vertex-Cover Problem
(Starbucks Problem)

* Given a city, is it possible to build stores on 𝑘 street corners so that every


street is “covered” by some store?
* (pick vertices to cover at least one end point of each edge)

* Problem: Given a graph 𝐺 and integer 𝑘 ≥ 0, is there a vertex-cover


of 𝐺 of size 𝑘?

𝐕𝐄𝐑𝐓𝐄𝐗−𝐂𝐎𝐕𝐄𝐑 = 𝐺, 𝑘 𝐺 is a graph w/ a vertex−cover of size 𝑘

street
street
corner
23
23

3SAT ≤! VERTEX−COVER
Goal: “translate” 𝜑 to 𝐺" , 𝑘" st:
• 𝜑 sat ⇒ 𝐺" has some 𝑘" -VC
• 𝜑 unsat ⇒ 𝐺" has no 𝑘" -VC

* Claim: 3SAT ≤3 VERTEX−COVER


* Proof idea:
* Given a 3CNF formula ϕ with 𝑛 variables, 𝑚 clauses:
* Make subgraphs (“gadgets”) that represent variables and clauses.
* Connect the gadgets together in the right way.

𝑧
𝑥 ¬𝑥 𝑥 ¬𝑦

Variable gadget for 𝑥 Clause gadget for (𝑥 ∨ ¬𝑦 ∨ 𝑧)


24

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 𝑥 𝑦 ¬𝑥 𝑦 𝑥 ¬𝑦

You might also like