Presentation on theme: "NP-complete and NP-hard problems"— Presentation transcript:
1 NP-complete and NP-hard problems Definition of complexity class NPNondeterministic computationProblems that can be verifiedThe P = NP QuestionConcept of NP-hard and NP-complete problems
2 Traditional definition of NP Turing machine model of computationSimple model where data is on an infinite capacity tapeOnly operations are reading char stored in current tape cell, writing a char to current tape cell, moving tape head left or right one squareDeterministic versus nondeterministic computationDeterministic: At any point in time, next move is determinedNondeterministic: At any point in time, several next moves are possibleNP: Class of problems that can be solved by a nondeterminstic turing machine in polynomial time
3 Turing MachinesA Turing machine has a finite-state-control (its program), a two way infinite tape (its memory) and a read-write head (its program counter)Finite StateControlHead….….111111Tape
4 Nondeterministic Running Time Nondeterministic ComputationDeterministic ComputationWe measure running time by looking at height of computation tree, NOT number of nodes exploredBoth computation have same height 4 and thus same running time
5 ND computation returning yes Yes ResultNo ResultIf any leaf node returns yes, we consider the input to be a yes input.If all leaf nodes return no, then we consider the input to be a no input.
6 Showing a problem is in NP Hamiltonian PathInput: Undirected graph G = (V,E)Y/N Question: Does G contain a HP?Nondeterministic polynomial-time solutionGuess a hamiltonian path P (ordering of vertices)V! possible orderingsFor binary tree, V log V height to generate all guessesVerify guessed ordering is correctReturn yes/no if ordering is actually a HP
8 Alternate definition of NP Preliminary DefinitionsLet P be a decision problemLet I be an input instance of PLet Y(P) be the set of yes input instances of PLet N(P) be the set of no input instances of PP belongs to NP iffFor any I e Y(P), there exists a “certificate” [solution] C(I) such that a deterministic algorithm can verify I e Y(P) in polynomial time with the help of C(I)For any I e N(P), no “certificate” [solution] C(I) will convince the algorithm that I e Y(P).
9 Connection 2 Guess Phase Nondeterministic --------------- 1 3 123132213231312321Guess PhaseNondeterministicVerify PhaseDeterministic123Yes input graphCertificate [Solution]A Hamiltonian PathC(I1): 123 or 321C(I2): noneVerification Alg:Verify certificate is a possible HPCheck for edge between all adjacent nodes in path123132213231312321Guess PhaseNondeterministicVerify PhaseDeterministic123No input graph
10 Example: Clique Problem Input: Undirected graph G = (V,E), integer kY/N Question: Does G contain a clique of size ≥ k?CertificateA clique C of size at least kVerification algorithmVerify this is a potential clique of size kVerify that all nodes in C are connected in E
11 Proving a problem is in NP You need to describe what the certificate C(I) will be for any input instance IYou need to describe the verification algorithmusually trivialYou need to argue that all yes input instances and only yes input instances have an appropriate certificate C(I)also usually trivial (typically do not require)
12 Example: Vertex Cover Vertex Cover Certificate Verification algorithm Input: Undirected graph G = (V,E), integer kY/N Question: Does G contain a vertex cover of size ≤ k?Vertex cover: A set of vertices C such that for every edge (u,v) in E, either u is in C or v is in C (or both are in C)CertificateA vertex cover C of size at most kVerification algorithmVerify C is a potential vertex cover of size at most kVerify that all edges in E contain a node in C
13 Example: Satisfiability Input: Set of variables X and set of clauses C over XY/N Question: Is there a satisfying truth assignment T for the variables in X such that all clauses in C are true?Certificate?Verification algorithm?
14 Example: Unsatisfiability Input: Set of variables X and set of clauses C over XY/N Question: Is there no satisfying truth assignment T for the variables in X such that all clauses in C are true?Certificate and Verification algorithm?Negative certificate and Negative verification algorithm?
15 Example: Exact Vertex Cover Input: Undirected graph G = (V,E), integer kY/N Question: Does the smallest vertex cover in G have size exactly k?Vertex cover: A set of vertices C such that for every edge (u,v) in E, either u is in C or v is in C (or both are in C)Certificate and Verification algorithm?Negative certificate and Negative verification algorithm?
16 NP-complete and NP-hard problems Definition of complexity class NPNondeterministic computationProblems that can be verifiedThe P = NP QuestionConcept of NP-hard and NP-complete problems
17 Definition of NP-hard A problem П is NP-hard if for all П’ e NP П’ ≤p П holds.Intuitively, an NP-hard problem П is at least as hard (defined by membership in P) as any problem in NP
18 Definition of NP-complete A problem П is NP-complete ifП is NP-hard andП is in NPIntuitively, an NP-complete problem П is the hardest problem in NPThat is, if П is in P, then P=NPIf P ≠ NP, then П is not in PP=NP=NP-completeNPPNP-completeOR
19 Importance of NP-completeness Importance of “Is P=NP” Question Practitioners viewThere exist a large number of interesting and seemingly different problems which have been proven to be NP-completeThe P=NP question represents the question of whether or not all of these interesting and different problems belong to PAs the set of NP-complete problems grows, the question becomes more and more interesting
20 List of Problem Types from Garey & Johnson, 1979 Graph TheoryNetwork DesignSets and PartitionsStorage and RetrievalSequencing and SchedulingMathematical ProgrammingAlgebra and Number TheoryGames and PuzzlesLogicAutomata and LanguagesProgram OptimizationMiscellaneous
21 Importance of NP-completeness Importance of “Is P=NP” Question Theoretician’s viewNP is exactly the set of problems that can be “verified” in polynomial timeThus “Is P=NP?” can be rephrased as follows:Is it true that any problem that can be “verified” in polynomial time can also be “solved” in polynomial time?Hardness ImplicationsIt seems unlikely that all problems that can be verified in polynomial time also can be solved in polynomial timeIf so, then P≠NPThus, proving a problem to be NP-complete is a hardness result as such a problem will not be in P if P≠NP.
22 Proving a problem П is NP-complete Show П is in NP (usually easy step)Prove for all П’ e NP П’ ≤p П holds.Show that П’ ≤p П for some NP-hard problemП’This only works if we have a known NP-hard problem П’ to reduce fromAlso depends on transitivity property proven earlierWe need to prove the existence of a first NP-hard problemCook-Levin ThmDeveloping new reductions is a skill or art formOver time, it gets easier
23 Select the right source problem 3-SAT: The old reliable. When none of the other problems seem to work, this is the one to come back to.Integer Partition: A good choice for number problems.3-Partition: A good choice for proving “strong” NP-completeness for number problems.Vertex Cover: A good choice for selection problems.Hamiltonian Path: A good choice for ordering problems.
24 Some historyCook: “The complexity of theorem-proving procedures” STOC 1971, ppPolynomial-time reductionsNP complexity classSAT is NP-completeLevin: “Universal sorting problems”, Problemi Peredachi Informatsii 9:3 (1973), ppIndependent discovery of many of the same ideasKarp: “Reducibility among combinatorial problems”, in Complexity of Computer Computations, 1972, ppShowed 21 problems from a wide variety of areas are NP-complete
25 P1 ≤p P2 & P2 ≤p P3 P1 ≤p P3Let R1 be the reduction used to prove P1 ≤p P2Let R2 be the reduction used to prove P2 ≤p P3Let x be an input to P1Define R3(x) to be R2(R1(x))
26 Answer-preserving argument Because R1 is a reduction between P1 and P2, we know that R1(x) is a yes input instance of P2 iff x is a yes input instance of P1Because R2 is a reduction between P2 and P3, we know that R2(R1(x)) is a yes input instance of P3 iff R1(x) is a yes input instance of P2Applying transitivity of iff, we get that R3(x) is a yes input of P3 iff x is a yes input instance of P1
27 Polynomial-time Argument Let R1 take time nc1Let R2 take time nc2Let n be the size of xThen the R1 call of R3 takes time at most nc1Furthermore, R1(x) has size at most max(n,nc1)Therefore, the R2 call of R3 takes time at most max(nc2, (nc1)c2) = max (nc2, nc1 c2)In either case, the total time taken by R3 is polynomial in n