0% found this document useful (0 votes)
26 views29 pages

CS341 Lec16 Annotated Mar26

UW CS341 Lec16

Uploaded by

artem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views29 pages

CS341 Lec16 Annotated Mar26

UW CS341 Lec16

Uploaded by

artem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

CS 341: Algorithms

Lec 16: NP-completeness

Armin Jamshidpey Yang Lu


Based on lecture notes by Lap Chi Lau, and many other CS 341 instructors

David R. Cheriton School of Computer Science, University of Waterloo

Winter 2024

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 1 / 11


NP Class

[CLRS]

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 2 / 11


NP Class

[CLRS]

For a problem X, we represent an instance of X as a binary


string S.
Definition: NP
A problem X is in NP, if there is a polynomial time
verification algorithm ALGX such that the input S is a
yes-instance iff there is a proof (certificate) t which is a binary
string of length poly(|S|) so that ALGX (S, t) returns yes.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 2 / 11


Examples

Example 1: Vertex Cover


S here is an input graph G = (V, E) and an integer k
t here is a subset U of V with |U | ≤ k
Algv (S, t): go through all E and check if t covers the edges and
t ≤ k.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 3 / 11


Examples

Example 1: Vertex Cover


S here is an input graph G = (V, E) and an integer k
t here is a subset U of V with |U | ≤ k
Algv (S, t): go through all E and check if t covers the edges and
t ≤ k.

Example 1: 3-SAT
S here is a 3-SAT formula
t here is a truth assignment
Algv (S, t): check whether t satisfies all clauses.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 3 / 11


Examples

Example 1: Vertex Cover


S here is an input graph G = (V, E) and an integer k
t here is a subset U of V with |U | ≤ k
Algv (S, t): go through all E and check if t covers the edges and
t ≤ k.

Example 1: 3-SAT
S here is a 3-SAT formula
t here is a truth assignment
Algv (S, t): check whether t satisfies all clauses.

Exercise: Clique, IS, HC, HP, Subset-Sum are all in NP.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 3 / 11


Remarks
1 Are all problems in NP? No.
Is a given graph non-Hamiltonian (i.e. no Hamiltonian Cycle)?

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 4 / 11


Remarks
1 Are all problems in NP? No.
Is a given graph non-Hamiltonian (i.e. no Hamiltonian Cycle)?
Definition
co-NP is the set of decision problems whose no-instances can be
certified in polynomial time.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 4 / 11


Remarks
1 Are all problems in NP? No.
Is a given graph non-Hamiltonian (i.e. no Hamiltonian Cycle)?
Definition
co-NP is the set of decision problems whose no-instances can be
certified in polynomial time.

2 Every polynomial time solvable decision problem is in NP.


Definition
P is the set of decision problems that can be solved in polynomial
time.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 4 / 11


Remarks
1 Are all problems in NP? No.
Is a given graph non-Hamiltonian (i.e. no Hamiltonian Cycle)?
Definition
co-NP is the set of decision problems whose no-instances can be
certified in polynomial time.

2 Every polynomial time solvable decision problem is in NP.


Definition
P is the set of decision problems that can be solved in polynomial
time.

P⊆ NP.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 4 / 11


Remarks
1 Are all problems in NP? No.
Is a given graph non-Hamiltonian (i.e. no Hamiltonian Cycle)?
Definition
co-NP is the set of decision problems whose no-instances can be
certified in polynomial time.

2 Every polynomial time solvable decision problem is in NP.


Definition
P is the set of decision problems that can be solved in polynomial
time.

P⊆ NP.
3 The most important open problem in theoretical computer
science: is P equal to NP?

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 4 / 11


Remarks
1 Are all problems in NP? No.
Is a given graph non-Hamiltonian (i.e. no Hamiltonian Cycle)?
Definition
co-NP is the set of decision problems whose no-instances can be
certified in polynomial time.

2 Every polynomial time solvable decision problem is in NP.


Definition
P is the set of decision problems that can be solved in polynomial
time.

P⊆ NP.
3 The most important open problem in theoretical computer
science: is P equal to NP?
4 The name NP comes from Non-deterministic Polynomial time.
A non-deterministic machine, roughly speaking, has the power to
correctly guess a solution.
A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 4 / 11
NP-completeness
informally we say a problem is NP-complete if it is the hardest
problem in NP.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 5 / 11


NP-completeness
informally we say a problem is NP-complete if it is the hardest
problem in NP.
NP-complete
A problem X ∈ NP is NP-complete if Y ≤P X for all Y ∈ NP.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 5 / 11


NP-completeness
informally we say a problem is NP-complete if it is the hardest
problem in NP.
NP-complete
A problem X ∈ NP is NP-complete if Y ≤P X for all Y ∈ NP.

Fact: P = NP ⇐⇒ an NP-complete problem can be solved in


polynomial time.
Theorem(Cook-Levin)
3-SAT is NP-complete.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 5 / 11


NP-completeness
informally we say a problem is NP-complete if it is the hardest
problem in NP.
NP-complete
A problem X ∈ NP is NP-complete if Y ≤P X for all Y ∈ NP.

Fact: P = NP ⇐⇒ an NP-complete problem can be solved in


polynomial time.
Theorem(Cook-Levin)
3-SAT is NP-complete.

Consequences:
If we can prove 3-SAT ≤P X, then X is NP-complete. For
example IS ∈ NPC, since 3-SAT≤P IS.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 5 / 11


NP-completeness
informally we say a problem is NP-complete if it is the hardest
problem in NP.
NP-complete
A problem X ∈ NP is NP-complete if Y ≤P X for all Y ∈ NP.

Fact: P = NP ⇐⇒ an NP-complete problem can be solved in


polynomial time.
Theorem(Cook-Levin)
3-SAT is NP-complete.

Consequences:
If we can prove 3-SAT ≤P X, then X is NP-complete. For
example IS ∈ NPC, since 3-SAT≤P IS.
To prove that a problem X ∈ NP is NP-complete, we just
need to find a NP-complete problem Y , and prove that
Y ≤P X.
A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 5 / 11
Circuit satisfiability
Circuit-SAT
instance: a circuit = DAG with labels on the vertices
inputs labelled by boolean variables x1 , . . . , xn .
internal vertices labelled by and, or, not
there is a marked vertex v for the output
problem: is there a choice of boolean xi that makes v true?

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 6 / 11


Plan to prove the Cook–Levin theorem

1 Show that Circuit-Sat is NP-complete

2 Show that Circuit-SAT ≤P 3-SAT.

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 7 / 11


Circuit-Sat is NP-complete (Sketch)
The idea
given: instance S of A ∈ NP

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 8 / 11


Circuit-Sat is NP-complete (Sketch)
The idea
given: instance S of A ∈ NP
want: proof (certificate) t such that ALGA (S, t) = true

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 8 / 11


Circuit-Sat is NP-complete (Sketch)
The idea
given: instance S of A ∈ NP
want: proof (certificate) t such that ALGA (S, t) = true
verification algorithm ALGA (S, t) can be turned into a
circuit with t as input

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 8 / 11


Circuit-Sat is NP-complete (Sketch)
The idea
given: instance S of A ∈ NP
want: proof (certificate) t such that ALGA (S, t) = true
verification algorithm ALGA (S, t) can be turned into a
circuit with t as input
we call Circuit-SAT to find t

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 8 / 11


Circuit-Sat is NP-complete (Sketch)
The idea
given: instance S of A ∈ NP
want: proof (certificate) t such that ALGA (S, t) = true
verification algorithm ALGA (S, t) can be turned into a
circuit with t as input
we call Circuit-SAT to find t

Example
problem A: IS
instance S: complete graph with 3 vertices, k = 2
certificate t: 3 bits y1 , y2 , y3 (yes/no for each vertex)
circuit for ALGA (S, t) computes the “formula”

(y1 + y2 + y3 ≥ 2) ∧ y1 ∧ y2 ∧ y1 ∧ y3 ∧ y2 ∧ y3

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 8 / 11


Circuit-SAT ≤P 3-SAT

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 9 / 11


CircuitSAT ≤P 3SAT

gives
     
y1 ⇐⇒ (x1 ∧x2 ) ∧ y2 ⇐⇒ (x2 ∨x3 ) ∧ v ⇐⇒ (y1 ∧y2 ) ∧ v

and

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 10 / 11


CircuitSAT ≤P 3SAT

gives
     
y1 ⇐⇒ (x1 ∧x2 ) ∧ y2 ⇐⇒ (x2 ∨x3 ) ∧ v ⇐⇒ (y1 ∧y2 ) ∧ v

and

F =(y1 ∨ x1 ∨ x2 ) ∧ (y1 ∨ x1 ) ∧ (y1 ∨ x2 ) ∧


(y2 ∨ x2 ) ∧ (y2 ∨ x3 ) ∧ (y2 ∨ x2 ∨ x3 ) ∧
(v ∨ y1 ∨ y2 ) ∧ (v ∨ y1 ) ∧ (v ∨ y2 ) ∧ v
A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 10 / 11
Some NP-complete problems

3SAT, SAT
independent set, vertex cover, clique
(directed) Hamiltonian cycle, Hamiltonian path
traveling salesman
subset sum
0/1 knapsack

A. Jamshidpey Y. Lu (CS, UW) Lec 16: NP-completeness Winter 2024 11 / 11

You might also like