np-complete proof of correctness; more reductions

20

Click here to load reader

Upload: alfredo-williard

Post on 11-Dec-2015

221 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: NP-Complete Proof of correctness; More reductions

NP-CompleteNP-Complete

Proof of correctness; More Proof of correctness; More reductionsreductions

Page 2: NP-Complete Proof of correctness; More reductions

DefinitionsDefinitions

P: problems that can be solved in P: problems that can be solved in polynomial polynomial timetime (typically in (typically in nn, size of input) on a , size of input) on a deterministic Turing machinedeterministic Turing machine Any normal computer simulates a DTMAny normal computer simulates a DTM

NP: problems that can be solved in NP: problems that can be solved in polynomial polynomial timetime on a on a non-deterministicnon-deterministic Turing machineTuring machine Informally, if we could “guess” the solution, we can Informally, if we could “guess” the solution, we can

verifyverify the solution in P time (on a DTM) the solution in P time (on a DTM) NP does NOT stand for NP does NOT stand for non-polynomialnon-polynomial, since there , since there

are problems harder than NPare problems harder than NP P is actually a subset of NP (we think)P is actually a subset of NP (we think)

Page 3: NP-Complete Proof of correctness; More reductions

Definitions, continuedDefinitions, continued

NP-hardNP-hard At least as hard as any known NP problem (could be At least as hard as any known NP problem (could be

harder!)harder!) Set of interrelated problems that can be solved by Set of interrelated problems that can be solved by

reducingreducing to another known problem to another known problem

NP-CompleteNP-Complete A problem that is in NP and NP-hardA problem that is in NP and NP-hard

Cook’s TheoremCook’s Theorem SATISFIABILITY (SAT) is NP-CompleteSATISFIABILITY (SAT) is NP-Complete

Other NP-Complete problemsOther NP-Complete problems Reduce to SAT or previous reduced problemReduce to SAT or previous reduced problem

Page 4: NP-Complete Proof of correctness; More reductions

Complexity Classes at-a-glanceComplexity Classes at-a-glance

Image taken from Jeff Erickson's lecture notes, Image taken from Jeff Erickson's lecture notes, http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/notes/21-nphard.pdfnotes/21-nphard.pdfWe will not discuss co-NP todayWe will not discuss co-NP today

Page 5: NP-Complete Proof of correctness; More reductions

CorrectnessCorrectness

To prove unknown problem To prove unknown problem y y is NP-is NP-Complete:Complete: Prove Prove yy is in NP is in NP Prove Prove yy is at least as hard as some is at least as hard as some xx in NP- in NP-

CompleteCompleteTransform Transform xx into into yy in polynomial time such that in polynomial time such that xx is is “yes” “yes” if and only ifif and only if yy is “yes” is “yes”

Requires two proofs, one for each direction: x yes Requires two proofs, one for each direction: x yes y y yes, y yes yes, y yes x yes (or x no x yes (or x no y no) y no)

Must also prove transformation is polynomialMust also prove transformation is polynomial

Page 6: NP-Complete Proof of correctness; More reductions

Example: Independent SetExample: Independent Set

Decision Problem: Decision Problem: is there a set of k is there a set of k vertices such that none are adjacent?vertices such that none are adjacent?

Proof of NP-Completeness:Proof of NP-Completeness: Is this in NP? Is this in NP?

Easy to check in k^2 (Adj. Matrix) or km (Adj. List)Easy to check in k^2 (Adj. Matrix) or km (Adj. List) Is this in NP-hard?Is this in NP-hard?

Reduce Reduce known known problem to problem to unknownunknown problem problem

NOT the other way!NOT the other way!

We will use 3-SATWe will use 3-SAT

Page 7: NP-Complete Proof of correctness; More reductions

ReductionsReductions

Always solve a Always solve a knownknown problem by transforming it into an problem by transforming it into an instance of the instance of the unknownunknown problem problem

Ex: 3SAT is NP-Complete. Independent Set is unknown. By Ex: 3SAT is NP-Complete. Independent Set is unknown. By transforming 3SAT into ISET and solving, we prove ISET is NP-transforming 3SAT into ISET and solving, we prove ISET is NP-CompleteComplete

If you go the other way, you might just make a bad If you go the other way, you might just make a bad transformation:transformation:

““Sorting” is an unknown. Transform sorting into 3SAT Sorting” is an unknown. Transform sorting into 3SAT (somehow) and solve. This does NOT mean sorting is NP-(somehow) and solve. This does NOT mean sorting is NP-Complete!Complete!

Think of it this way: “If I can solve Think of it this way: “If I can solve xx by transforming by transforming xx into into yy, then , then yy is is at least as hard asat least as hard as x.x.” ” (Corollary: if (Corollary: if yy can be solved quickly, so can can be solved quickly, so can xx.).)

Page 8: NP-Complete Proof of correctness; More reductions

3-SAT 3-SAT ≤≤pp ISET ISET

v1 v3

v2

v2 v4

v1

v4 v5

v2

v4 v5

v3

C = {v1, v2, v3} , {v1, v2, v4} ,{v2, v4, v5} , {v3, v4, v5}

For more details, review Lecture 18.

This is a slightly modified version that does not use the “Literal widgets” but just connects each node directly to any node that is its complement.

Page 9: NP-Complete Proof of correctness; More reductions

3-SAT to ISET, continued3-SAT to ISET, continued

The The size of the transformationsize of the transformation on the last slide is polynomial in the on the last slide is polynomial in the number of clauses (m) + number of literals (n) number of clauses (m) + number of literals (n) Adding Adding opposing literals edges opposing literals edges in the worst-case (full exploration of in the worst-case (full exploration of graph for each vertex) is still polynomial in mgraph for each vertex) is still polynomial in m², so the ², so the time of the time of the transformation transformation is also polynomialis also polynomialNow we must prove 3SAT “yes” Now we must prove 3SAT “yes” ISET “yes” ISET “yes”3SAT 3SAT ISET ISET

Set target size for ISET = mSet target size for ISET = m Identify only Identify only oneone “true” literal in each clause of 3SAT, select that vertex “true” literal in each clause of 3SAT, select that vertex

in that “triangle” in ISET. Our set has no edges between nodes in the in that “triangle” in ISET. Our set has no edges between nodes in the same triangle.same triangle.

Because this is a legal TA for 3SAT, we can’t select a complementary Because this is a legal TA for 3SAT, we can’t select a complementary version of a previously selected literal, so no edges will connect nodes version of a previously selected literal, so no edges will connect nodes in different triangles.in different triangles.

Page 10: NP-Complete Proof of correctness; More reductions

Visual demonstration of Visual demonstration of 3SAT 3SAT ISET ISET

CC = = {{vv1, 1, vv22, , vv3} , {3} , {vv11, , vv2, 2, vv4} ,4} ,

{{vv2, 2, vv4, 4, vv55} , {} , {vv33, , vv4, 4, vv5}5}

Select nodes corresponding to literals in Select nodes corresponding to literals in violet. violet. These form an independent set of These form an independent set of size m.size m.

v1 v3

v2

v2 v4

v1

v4 v5

v2

v4 v5

v3

Page 11: NP-Complete Proof of correctness; More reductions

3SAT 3SAT ISET ISET

So we have an ISET of size So we have an ISET of size mm, how does , how does this give us a valid TA for 3SAT?this give us a valid TA for 3SAT? At most one node comes from each triangleAt most one node comes from each triangle There are There are mm triangles, so there must be one triangles, so there must be one

node in every triangle node in every triangle mm clauses covered clauses covered Because of the opposing literals edges, no Because of the opposing literals edges, no

conflicting truth assignments can be in ISETconflicting truth assignments can be in ISET Assign the literals in the ISET to true; other Assign the literals in the ISET to true; other

literals don’t matterliterals don’t matter

Page 12: NP-Complete Proof of correctness; More reductions

Hamiltonian Path & H. CycleHamiltonian Path & H. Cycle

In Lecture 18, a (complex) proof was given that In Lecture 18, a (complex) proof was given that HAMCYCLE (aka TSP) was NP-CompleteHAMCYCLE (aka TSP) was NP-Complete

How can we show that HAMPATH is also NP-How can we show that HAMPATH is also NP-Complete?Complete? Take graph G and modify to G'Take graph G and modify to G'

Show transformation is polynomialShow transformation is polynomial Show that G' has HAMPATH if G has HAMCYCLEShow that G' has HAMPATH if G has HAMCYCLE Show that G has HAMCYCLE if G' has HAMPATHShow that G has HAMCYCLE if G' has HAMPATH

Page 13: NP-Complete Proof of correctness; More reductions

HAMPATH/HAMCYCLE, cont'dHAMPATH/HAMCYCLE, cont'd

Run HAMPATH on G'Run HAMPATH on G' If G had a HAMCYCLE, G' has a path through all the vertices If G had a HAMCYCLE, G' has a path through all the vertices

except V1' and V2' starting at V1 and ending at V2 that except V1' and V2' starting at V1 and ending at V2 that corresponds to the cycle. Add V1' to the start of the path, V2' to corresponds to the cycle. Add V1' to the start of the path, V2' to the end, and it's a HAMPATH.the end, and it's a HAMPATH.

If G' has a HAMPATH, it must start/end at V1'/V2' since they If G' has a HAMPATH, it must start/end at V1'/V2' since they have degree 1, so G has a HAMCYCLE starting from Vhave degree 1, so G has a HAMCYCLE starting from V

GV

Split any vertex V into two identical vertices V1 and V2 (do not create E(V1,V2)).

G'

V1

V2

V1'

V2'

Then create V1' and V2' adjacent only to V1 and V2, respectively.

(The transformation is trivially polynomial.)

Page 14: NP-Complete Proof of correctness; More reductions

Hitting SetHitting Set

Problem, given a set T of sets sProblem, given a set T of sets s11, s, s22 … s … snn, ,

is there a set H of at most k elements such is there a set H of at most k elements such that H contains at least one element from that H contains at least one element from every severy s11…s…snn??

Example: T = {{1,2,3},{a,1},{a,b,c},{Example: T = {{1,2,3},{a,1},{a,b,c},{}}}} k=2, no valid H!k=2, no valid H! k=3, H = {1,a,k=3, H = {1,a,} (other choices exist)} (other choices exist)

How hard is this problem?How hard is this problem?

Page 15: NP-Complete Proof of correctness; More reductions

Hitting Set ComplexityHitting Set Complexity

Easy to show problem is in NP: would take at Easy to show problem is in NP: would take at most nk time to verify a given solution Hmost nk time to verify a given solution HIs this NP-Complete?Is this NP-Complete? Think about other problems you know are NP-Think about other problems you know are NP-

Complete: SAT (and cousins), Independent Set, Complete: SAT (and cousins), Independent Set, HP/HC, Vertex Cover (worksheet), Maximum Clique HP/HC, Vertex Cover (worksheet), Maximum Clique (worksheet)(worksheet)

Look for a similar problem: something that involves Look for a similar problem: something that involves selecting one item to represent some collection of selecting one item to represent some collection of itemsitems

Work in groups to find a reduction and argue Work in groups to find a reduction and argue that it is correctthat it is correct

Page 16: NP-Complete Proof of correctness; More reductions

Vertex Cover Vertex Cover ≤≤pp Hitting Set Hitting Set

Both involve "select some items such that Both involve "select some items such that all items are represent"all items are represent"Construct: Given a graph G, for each edge Construct: Given a graph G, for each edge e = (u,v) create a set s = {u,v} and add s to e = (u,v) create a set s = {u,v} and add s to the universe T. the universe T. Now prove G has a vertex cover of size k Now prove G has a vertex cover of size k T has a hitting set of size k T has a hitting set of size k Select k vertices to represent m edges vs. Select k vertices to represent m edges vs.

select k elements to represent m setsselect k elements to represent m sets

Page 17: NP-Complete Proof of correctness; More reductions

Vertex Cover Vertex Cover Hitting Set Hitting Set

Vertex Cover Vertex Cover Hitting Set Hitting Set Suppose C is a cover of G of size k Suppose C is a cover of G of size k

By definition then, for every edge (u,v) in G, either By definition then, for every edge (u,v) in G, either u u C or v C or v C CThen H can be set to C, and H must intersect Then H can be set to C, and H must intersect every set in T.every set in T.

Vertex Cover Vertex Cover Hitting Set Hitting Set Suppose H is a hitting set of T of size kSuppose H is a hitting set of T of size k

Since H intersects every set, it has at least one Since H intersects every set, it has at least one endpoint of every edge. Set C to be H.endpoint of every edge. Set C to be H.

Page 18: NP-Complete Proof of correctness; More reductions

Set CoverSet Cover

Problem, given a set T of sets sProblem, given a set T of sets s11, s, s22 … s … snn, , is there a set is there a set S'S' of at most k sets such that of at most k sets such that S'S' contains every element in T? contains every element in T?Example: T = {{1,2,3},{a,1},{a,b,c},{Example: T = {{1,2,3},{a,1},{a,b,c},{}}}} k = 2, no legal S'!k = 2, no legal S'! k = 3, S' = {{1,2,3},{a,b,c},{k = 3, S' = {{1,2,3},{a,b,c},{}}}}

This should look very familiar! This should look very familiar! Work in groups to find a reduction and Work in groups to find a reduction and argue that it is correctargue that it is correct

Page 19: NP-Complete Proof of correctness; More reductions

Vertex Cover Vertex Cover ≤≤pp Set Cover Set Cover

Given a graph G, construct a universe of Given a graph G, construct a universe of sets T:sets T: For each vertex V, create a set sFor each vertex V, create a set svv with all the with all the

edges incident on Vedges incident on V Our “universe” is now the set of all edges in G Our “universe” is now the set of all edges in G

(each is listed twice)(each is listed twice)

B C

A

E F

DT = {{ab,ac,ae},{ba,bc,bd},{ca,cb},{db,de,df},{ea,ed,ef},{fd,fe}}

Page 20: NP-Complete Proof of correctness; More reductions

Vertex Cover Vertex Cover Set Cover Set Cover

Vertex Cover Set Cover Suppose C is a cover of G of size k

To find S', select sets sw for every w C.

If there was an edge e=(u,v) in T not in S', then neither su nor sv was selected, so neither u nor v was in the Vertex Cover, a contradiction.

Vertex Cover Set Cover Suppose S' is a set cover of T of size k

To find C, select vertex v for every sv S'If there is an edge e=(u,v) in G not in C, then neither vertex u nor v was selected, so neither su nor sv was in S'. Since {uv} can only be found in su and sv this contradicts that S' is a cover.