powerpoint presentation · a capacity budget c a value v is there an s’ µ{1,…,n} such that ......

29
1 Lecture 18: More NP-Complete Problems 6.045

Upload: doandiep

Post on 03-Nov-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

1

Lecture 18:More NP-Complete Problems

6.045

2

The Clique Problem

b

a

e

c

d f

g

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 }

3

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

4

Theorem: CLIQUE is NP-Complete

PNP

3SAT

CLIQUE

5

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?

6

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 G with 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

7

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

x1 x1

x1 x2

x2 x2

x2 x2

x1

k = number of clauses|V| = 3(number of clauses)

8

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

x1

x1

x2

x2

x1 x1

x2 x2

x1 x2

x2

x1

9

Claim: 3SAT (G,m) CLIQUE

Claim: If 3SAT then (G,m) CLIQUEProof: Let A be a SAT assignment of .For every clause C of , some literal in C is set true by A

For every clause C, let vC be a vertex from group C of G, whose label is a literal that is set true by A

Claim: S = {vC | C 2 } is an m-clique in G. (note |S|=m)

Proof: Let vC,vC’ be in S. If (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’) 2 E, for all vC, vC’2 S.

Hence S is an m-clique, and (G,m) CLIQUE

10

Claim: If (G,m) CLIQUE then 3SATProof: Let S be an m-clique of G.

We’ll construct a satisfying assignment A of .

Claim: S contains exactly one node from each group.

For each variable x of , make variable assignment: A(x) := 1, if there is a vertex v ϵ S with label xA(x) := 0, otherwise

For all i = 1,…,m, one vertex from group i is in S. Therefore, for all i = 1,…,m

A satisfies at least one literal in the ith clause of Therefore A is a satisfying assignment to

Claim: 3SAT (G,m) CLIQUE

11

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?

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) 2 CLIQUE iff (G’, k) 2 IS

12

The Vertex Cover Problem

b

a

e

c

d

b

a

e

c

d

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

13

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

14

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

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

IS P VERTEX-COVER

15

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 2 V)[ (u 2 S and v 2 S) ) (u,v) ∉ E ] (8 u, v 2 V)[ (u,v) 2 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)

16

Theorem: There is a O(n ⋅ t) time algorithmfor solving SUBSET-SUM.

But t can be specified in (log t) bits… this isn’t an algorithm that runs in polytime in the input!

The Subset Sum Problem

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

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

SUBSET-SUM = {(S, t) | 9 S’ µ S s.t. t = b 2 S’ b }

A simple number-theoretic problem!

17

The Subset Sum Problem

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

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

SUBSET-SUM = {(S, t) | 9 S’ µ S s.t. t = b 2 S’ b }

A simple number-theoretic problem!

Theorem: SUBSET-SUM is NP-complete

18

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 ej

4j in S

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

19

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 t = k ¢ 4m + j=0m-1 (2 ¢ 4j)

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

Suppose 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

20

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=0

m-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 t = k ¢ 4m + j=0m-1 (2 ¢ 4j)

21

The Knapsack Problem

Given: S = {(v1,c1)…, (vn,cn)} of pairs of positive integers a capacity budget Ca value V

Is there an S’ µ {1,…,n} such that

(i 2 S’ vi ) ≥ V and (i 2 S’ ci ) ≤ C ?

Define KNAPSACK = {(S, C, V) | the answer is yes}

A classic economics/logistics problem!

Theorem: KNAPSACK is NP-complete

22

KNAPSACK is NP-complete

KNAPSACK is in NP?

Theorem: SUBSET-SUM P KNAPSACK

Proof: Given an instance (S = {a1,…,an}, t) of SUBSET-SUM, create a KNAPSACK instance:

For all i, set (pi, ci) := (ai, ai)Define T = {(p1, c1),…, (pn, cn)}

Define C := P := t

Then, (S,t) 2 SUBSET-SUM (T,C,P) 2 KNAPSACK

Subset of S that sums to t =Solution to the Knapsack instance!

23

The Partition Problem

Given: Set S = {a1,…, an} of positive integers

Is there an S’ µ S such that (a_i 2 S’ ai) = (a_i 2 S-S’ ai)?

(Formally, PARTITION is the set of all S such that the answer to this question is yes.)

In other words, is there a way to partition S intotwo parts, with equal sum in both parts?

A problem in fair division

Theorem: PARTITION is NP-complete

24

PARTITION is NP-complete

(1) PARTITION is in NP

(2) SUBSET-SUM P PARTITION

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

Output T := {a1,…, an,2A-t,A+t}, where A := i ai

Claim: (S,t) 2 SUBSET-SUM ⇔ T 2 PARTITION

25

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

Output T := {a1,…, an,2A-t,A+t}, where A := i ai

Claim: (S,t) 2 SUBSET-SUM ⇔ T 2 PARTITION

What’s the sum of all numbers in T? 4A

Therefore: T 2 PARTITION⇔ There is a T’ µ T that sums to 2A.

Proof of: (S,t) 2 SUBSET-SUM ⇒ T 2 PARTITION:

If (S,t) 2 SUBSET-SUM, let S’ µ S sum to t.Then S’ {2A-t} µ T sums to 2A, so T 2 PARTITION

26

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

Output T := {a1,…, an,2A-t,A+t}, where A := i ai

Claim: (S,t) 2 SUBSET-SUM ⇔ T 2 PARTITION

T 2 PARTITION ⇔ There is a T’ µ T that sums to 2A.

Proof of: T 2 PARTITION ⇒ (S,t) 2 SUBSET-SUM

If T 2 PARTITION, let T’ µ T be a subset that sums to 2A.

Observation: Exactly one of {2A-t,A+t} is in T’.

If (2A-t) 2 T’, then T’ – {2A-t} sums to t.But T’ – {2A-t} is a subset of S! So (S,t) 2 SUBSET-SUM

If (A+t) 2 T’, then (T – T’) – {2A-t} sums to (2A – (2A-t)) = t

Note that (T – T’) – {2A-t} is a subset of S.Therefore (S,t) 2 SUBSET-SUM

27

The Bin Packing Problem

Given: Set S = {a1,…, an} of positive integers, a bin capacity B, and a target integer K.Can we partition S into K subsets such that

each subset sums to at most B?

Is there a way to pack the items of S into K bins, with each bin having capacity B?

Ubiquitous in shipping and optimization

Theorem: BIN PACKING is NP-complete

28

BIN PACKING is NP-complete

BIN PACKING is in NP?

Theorem: PARTITION P BIN PACKING

Proof: Given an instance S = {a1,…, an} of PARTITION,create an instance of BIN PACKING with:

S = {a1,…, an}B = (i ai)/2

k = 2

Then, S 2 PARTITION (S,B,k) 2 BIN PACKING:

Partition of S into two equal sums =Solution to the Bin Packing instance!

29

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?