24
More NP-Completeness CS 154, Omer Reingold

More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

More NP-Completeness

CS 154, Omer Reingold

Page 2: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

There are thousands of NP-complete problems

Your favorite topic certainly has an NP-complete problem somewhere in it

Even the other sciences are not safe: biology, chemistry, physics have NP-complete problems too!

Page 3: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Given a favorite problem NP, how can we prove it is NP-hard?

Generic Recipe:1. Take a problem that you know to be NP-hard (3-SAT)2. Prove that P

Then for all A NP, A P and P

We conclude that A P , and is NP-hard

Page 4: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

is NP-Complete

PNP

Page 5: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

The Clique Problem

Given a graph G and positive k, does G contain a complete subgraph on k nodes?

CLIQUE = { (G,k) | G is an undirected graph with a k-clique }

Theorem (Karp): CLIQUE is NP-complete

Page 6: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Proof Idea: 3SAT P CLIQUE

Transform a 3-cnf formula into (G,k) such that

3SAT (G,k) CLIQUE

Want transformation that can be done in time that is polynomial in the length of

How can we encode a logic problem as a graph problem?

Page 7: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

3SAT P CLIQUE

We transform a 3-cnf formula into (G,k) such that

3SAT (G,k) CLIQUE

Let C1, C2, …, Cm be clauses of . Assign k := m. Make a graph Gwith m groups of 3 nodes each.

Group i corresponds to clause Ci of . Each node in group i is labeled with a literal of Ci

Put no edges between nodes in the same group

Put edges between all pairs of nodes in different groups, except pairs of nodes with labels 𝑥𝑖 and 𝑥𝑖

When done putting in all the edges, erase the labels

Page 8: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

(x1 x1 x2) (x1 x2 x2) (x1 x2 x2)

x1 x1

x1 x2

x2 x2

x2 x2

x1

k = 3|V| = 9

Page 9: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

(x1 x1 x1) (x1 x1 x2) (x2 x2 x2) (x2 x2 x1)

x1

x1

x2

x2

x1 x1

x2 x2

x1 x2

x2

x1

Page 10: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Claim: 3SAT (G,m) CLIQUE

Claim: If 3SAT then (G,m) CLIQUEProof: Given a SAT assignment A of , for every clause C there is at least one literal in C that’s set true by AFor each clause C, let vC be a vertex from group Cwhose label is a literal that is set true by A

Claim: S = {vC : C } is an m-cliqueProof: Let vC,vC’ be in S. Suppose (vC,vC’) ∉ E.Then vC and vC’ must label inconsistent literals, call them x and xBut assignment A cannot satisfy both x and x

Therefore (vC,vC’) E, for all vC, vC’ S.Hence S is an m-clique, and (G,m) CLIQUE

Page 11: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Claim: If (G,m) CLIQUE then 3SATProof: Let S be an m-clique of G. We construct a satisfying assignment A of .

Claim: S contains exactly one node from each group.

Now for each variable x of , make assignment A: Assign x to 1 There is a vertex v ϵ S with label x

For all i = 1,…,m, at least one vertex from group i is in S. Therefore, for all i = 1,…,m. A satisfies at least one literal in the ithclause of . Therefore A is a satisfying assignment to

Claim: 3SAT (G,m) CLIQUE

Page 12: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Independent Set

IS: Given a graph G = (V, E) and integer k, is there S V such that |S|=k and no two vertices in S have an edge?IS = {(G,k) | G is an undirected graph with an IS of size k}

CLIQUE: Given G = (V, E) and integer k, is there S V such that |S|=k and every pair of vertices in S have an edge?

CLIQUE ≤P IS:Given G = (V, E), output G’ = (V, E’) where E’ = {(u,v) | (u,v) ∉ E}.

(G, k) CLIQUE iff (G’, k) IS

Page 13: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

The Vertex Cover Problem

b

a

e

c

d

b

a

e

c

d

vertex cover = set of nodes C that cover all edges:For all edges, at least one endpoint is in C

Page 14: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

VERTEX-COVER = { (G,k) | G is a graph with a vertex cover of size at most k}

Theorem: VERTEX-COVER is NP-Complete

(1) VERTEX-COVER NP

(2) IS P VERTEX-COVER

Page 15: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Want to transform a graph G and integer k into G’ and k’ such that

(G,k) IS (G’,k’) VERTEX-COVER

IS P VERTEX-COVER

Page 16: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Claim: For every graph G = (V,E), and subset S V, S is an independent set if and only if (V – S) is a vertex cover

Therefore (G,k) IS (G,|V| – k) VERTEX-COVER

Proof: S is an independent set (8 u, v V)[ (u S and v S) ) (u,v) ∉ E ] (8 u, v V)[ (u,v) E ) (u ∉ S or v ∉ S) ]

(V – S) is a vertex cover

IS P VERTEX-COVER

Our polynomial time reduction: f(G,k) := (G, |V| – k)

Page 17: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

The Subset Sum Problem

Given: Set S = {a1,…, an} of positive integers and a positive integer t

Is there an A µ {1, … ,n} such that t = i 2 A ai ?

SUBSET-SUM = {(S, t) | 9 A µ S s.t. t = i 2 A ai }

A simple number-theoretic problem

Theorem: SUBSET-SUM is NP-complete

Note: There is an O(n ⋅ t) time algorithm for Subset Sum.Does this prove P=NP?

Page 18: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

VC P SUBSET-SUM

Want to reduce a graph to a set of numbers

Given (G, k), let E = {e0,…,em-1} and V = {1,…,n}

Our subset sum instance (S, t) will have |S| = n+m

“Edge numbers”: For every ej 2 E, put bj = 4j in S

“Node numbers”: For every i 2 V, put ai = 4m + j : i 2 ej4j in S

Set the target number: t = k ¢ 4m + j=0m-1 (2 ¢ 4j)

Page 19: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

For every ej 2 E, put bj = 4j in S

For every i 2 V, put ai = 4m + j : i 2 ej4j in S

Set the target number: t = k ¢ 4m + j=0m-1 (2 ¢ 4j)

Claim: If (G,k) VC then (S,t) SUBSET-SUMSuppose C µ V is a VC with k vertices.Let S’ = {ai : i 2 C} {bj : |ej \ C| = 1}

S’ = (node numbers corresponding to nodes in C) plus(edge numbers corresponding to edges covered only once by C)

Claim: The sum of all numbers in S’ equals t

Think of the numbers as being in “base 4”… as vectors with m+1 components

Page 20: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Claim: If (S,t) SUBSET-SUM then (G,k) VC

Suppose C µ V and F µ E satisfyi 2 C ai + ej 2 F b

j= t = k ¢ 4m + j=0

m-1 (2 ¢ 4j)

Claim: C is a vertex cover of size k.Proof: Subtract out the bj numbers from the above sum. What remains is a sum of the form:

i 2 C ai = k ¢ 4m + j=0m-1 (cj ¢ 4j)

where each cj > 0. But cj = number of nodes in C covering ej

This implies C is a vertex cover!

For every ej 2 E, put bj = 4j in S

For every i 2 V, put ai = 4m + j : i 2 ej4j in S

Set the target number: t = k ¢ 4m + j=0m-1 (2 ¢ 4j)

Page 21: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Finding Paths - Two Problems

Let G denote a graph, and s and t denote nodes.

SHORTEST PATH = {(G, s, t, k) | G has a simple path of length < k from s to t }

LONGEST PATH= {(G, s, t, k) | G has a simple path of length > k from s to t }

Are either of these in P? Are both of them?

Page 22: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

HAMPATH = { (G,s,t) | G is an directed graph with a Hamiltonian path from s to t}

Theorem: HAMPATH is NP-Complete

(1) HAMPATH NP

(2) 3SAT P HAMPATH

See Sipser for the proof

Page 23: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

HAMPATH P LONGEST-PATH

LONGEST-PATH= {(G, s, t, k) | G has a simple path of length > k from s to t }

Can reduce HAMPATH to LONGEST-PATH by observing:

(G, s, t) 2HAMPATH (G, s, t, |V|) 2 LONGEST-PATH

Therefore LONGEST-PATH is NP-hard.

Page 24: More NP-Completeness - WordPress.com · 2020. 10. 27. · Given a favorite problem NP, how can we prove it is NP-hard? Generic Recipe: 1. Take a problem that you know to be NP-hard

Parting thoughts:

This is just the tip of the iceberg.

How do we cope with NP-Completeness?