1 / 37

NP-Complete Problems

NP-Complete Problems. CSC 331 : Algorithm Analysis. NP-Complete Problems. Search Problems. In past problems, we were searching for a solution from among an exponential population of possibilities. A graph with n vertices has n n-2 spanning trees.

awena
Télécharger la présentation

NP-Complete Problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NP-Complete Problems CSC 331: Algorithm Analysis NP-Complete Problems

  2. Search Problems In past problems, we were searching for a solution from among an exponential population of possibilities. A graph with n vertices has nn-2 spanning trees. A typical graph has an exponential number of paths from s to t. These problems could have been solved in exponential time by checking all candidate solutions. CSC 331: Algorithm Analysis NP-Complete Problems

  3. Search Problems An algorithm whose running time is 2n, or worse is all but useless in practice. The quest for efficient algorithms is about finding clever ways to bypass this process of exhaustive search. We have seen a number of algorithmic techniques that defeat exponentiality: greedy, dynamic programming, divide-and-conquer CSC 331: Algorithm Analysis NP-Complete Problems

  4. Search Problems Now we will look at some “search problems” in which the fastest known algorithms are exponential. Exponential solutions are said to be “intractable”. CSC 331: Algorithm Analysis NP-Complete Problems

  5. Satisfiability (SAT) This is a Boolean formula in conjunctive normal form. A satisfying truth assignment is an assignment of false or true to each variable so that every clause contains a literal whose value is true. • SAT: given a Boolean formula in CNF, either find a • satisfying truth assignment or else report that none exists. CSC 331: Algorithm Analysis NP-Complete Problems

  6. Satisfiability (SAT) Is there a truth assignment that satisfies all clauses? CSC 331: Algorithm Analysis NP-Complete Problems

  7. Satisfiability (SAT) SAT is a typical search problem: • We are given an instance I, and asked to find a solution S. If no such solution exists, say so. A search problem must have the property that any proposed solution S to an instance I can be quickly checked for correctness. • For SAT: check whether the assignment specified by • S indeed satisfies every clause in I. CSC 331: Algorithm Analysis NP-Complete Problems

  8. Search Problems A search problem is specified by an algorithm C that takes two inputs, an instance I and a proposed solution S, and runs in time polynomial in |I|. We say S is a solution to I if and only if C(I, S) =true. CSC 331: Algorithm Analysis NP-Complete Problems

  9. Satisfiability (SAT) Researchers over the past 50 years have tried hard to find efficient ways to solve SAT. The fastest algorithms we have are still exponential on their worst-case inputs. CSC 331: Algorithm Analysis NP-Complete Problems

  10. Satisfiability (SAT) There are two natural variants of SAT for which we do have good algorithms. • If all clauses contain at most one positive literal, then the Boolean formula is called a Horn formula, and a satisfying truth assignment, if one exists, can be found by a greedy algorithm. • If all clauses have only two literals, then SAT can be solved in linear time by finding the strongly connected components of a particular graph. CSC 331: Algorithm Analysis NP-Complete Problems

  11. Satisfiability (SAT) If we allow clauses to contain three literals, then the resulting problem (3SAT) once again becomes hard to solve. CSC 331: Algorithm Analysis NP-Complete Problems

  12. Traveling Salesperson Problem (TSP) Given n vertices 1, ..., n and all n(n - 1)/2 distances between them, as well as a budget, find a tour of total cost b or less, or report that no such tour exists. A tour is a cycle that passes through every vertex exactly once. CSC 331: Algorithm Analysis NP-Complete Problems

  13. Traveling Salesperson Problem (TSP) 5 3 2 3 3 4 1 4 3 2 6 CSC 331: Algorithm Analysis NP-Complete Problems

  14. Traveling Salesperson Problem (TSP) Algorithm 1: try all (n - 1)! tours. Algorithm 2: dynamic programming • For a subset of cities S ⊆ {1, 2, ..., n} that includes 1, and j ∈ S, let C(S, j) be the length of the shortest path visiting each node in S exactly once starting at 1 and ending at j. CSC 331: Algorithm Analysis NP-Complete Problems

  15. Traveling Salesperson Problem (TSP) • C({1},1) = 0 • for s = 2 to n: • for all subsets S ⊆ {1,2,...,n} of size s and containing 1: • C(S,1) = ∞ • for all j∈S, j≠1: • C(S,j) = min{C(S-{j},i) + dij : i∈S, i≠j} • return minj C({1,...,n},j) + dj1 O(n22n) CSC 331: Algorithm Analysis NP-Complete Problems

  16. Northern bank Small island Big island Southern bank Konigsberg Bridge Problem In 1735, Euler was walking the bridges of Konigsberg. He noticed that it seemed impossible to cross each bridge exactly once. CSC 331: Algorithm Analysis NP-Complete Problems

  17. Konigsberg Bridge Problem We are looking for a path that goes through each edge exactly once (the path is allowed to repeat vertices). In other words, when can a graph be drawn without lifting the pencil from the paper? If and only if: (a) the graph is connected (b) every vertex, with the possible exception of two vertices, has even degree CSC 331: Algorithm Analysis NP-Complete Problems

  18. Knight’s Tour (Rudrata or Hamiltonian) Can one visit all the squares of the chessboard, without repeating any square, in one long walk that ends at the starting square and at each step makes a legal knight move? This is a graph problem: • Graph has 64 vertices, and two squares are joined by an edge if a knight can go from one to the other in a single move. • Find a cycle that goes through all vertices, without repeating any vertex. CSC 331: Algorithm Analysis NP-Complete Problems

  19. Knight’s Tour (Rudrata or Hamiltonian) This problem is similar to TSP. No polynomial algorithm is known for it. Note that the main difference between Konigsburg (Euler) and Knight’s Tour (Rudrata) is that Euler visits all edges while Rudrata visits all vertices. CSC 331: Algorithm Analysis NP-Complete Problems

  20. Longest Path We know the shortest-path problem can be solved very efficiently, but how about the longest path problem? To avoid trivial solutions we require that the path be simple, containing no repeated vertices. No efficient algorithm is known for this problem. CSC 331: Algorithm Analysis NP-Complete Problems

  21. Graph coloring Given a graph and k colors, can you color every vertex so that no edge connects vertices of the same color? CSC 331: Algorithm Analysis NP-Complete Problems

  22. P and NP A search problem is specified by an algorithm C that takes two inputs, an instance I and a proposed solution S, and runs in time polynomial in |I|. We say S is a solution to I if and only if C(I, S) =true. Moreover the running time of C(I, S) is bounded by a polynomial in |I|, the length of the instance. CSC 331: Algorithm Analysis NP-Complete Problems

  23. P and NP We denote the class of all search problems by NP. The class of all search problems that can be solved in polynomial time is denoted P. Are there any search problems that cannot be solved in polynomial time? CSC 331: Algorithm Analysis NP-Complete Problems

  24. P and NP In other words, is P ≠ NP? • Most algorithms researchers think so. • The task of finding a proof for a given mathematical assertion is a search problem and is therefore in NP. • So if P = NP, there would be an efficient way to prove theorems, thus eliminating the need for mathematicians! CSC 331: Algorithm Analysis NP-Complete Problems

  25. P and NP There are a variety of reasons why it is widely believed that P ≠ NP. However, proving this has turned out to be extremely difficult, one of the deepest and most important unsolved puzzles in mathematics. CSC 331: Algorithm Analysis NP-Complete Problems

  26. P and NP P stands for “polynomial”. NP stands for “nondeterministic polynomial time”. • It means that a solution to any search problem can be found and verified in polynomial time by a special sort of algorithm, called a nondeterministic algorithm. • Such an algorithm has the power of guessing correctly at every step. CSC 331: Algorithm Analysis NP-Complete Problems

  27. P and NP CSC 331: Algorithm Analysis NP-Complete Problems

  28. P and NP Even if we accept that P ≠ NP, on what evidence do we believe that the listed hard problems have no efficient algorithm. Such evidence is provided by reductions, which translate one search problem into another. They demonstrate that the problems are all, in some sense, exactly the same problem, except they are stated in different languages. CSC 331: Algorithm Analysis NP-Complete Problems

  29. P and NP We can also use reductions to show that these problems are the hardest search problems in NP. If even one of these problems has a polynomial time algorithm, then every problem in NP has a polynomial time algorithm. Thus if we believe P ≠ NP, then all these search problems are hard. CSC 331: Algorithm Analysis NP-Complete Problems

  30. P and NP A reduction from search problem A to search problem B: • a polynomial-time algorithm f that transforms any instance I of A into an instance f(I) of B, • a polynomial-time algorithm h that maps any solution S of f(I) back into a solution h(S) of I. A search problem is NP-complete if all other search problems reduce to it. CSC 331: Algorithm Analysis NP-Complete Problems

  31. Reductions The book shows that the following search problems can be reduced to one another. As a consequence, they are all NP-complete. CSC 331: Algorithm Analysis NP-Complete Problems

  32. Reduction Example Lpath(G, a, b, k) is a decision problem – is there a simple path from a to b in G of length at least k? Show Lpath is NP-Complete. CSC 331: Algorithm Analysis NP-Complete Problems

  33. Reduction Example Lpath(G, a, b, k) is a decision problem – is there a simple path from a to b in G of length at least k? Show Lpath is NP-Complete. Hint: Use Hamiltonian Paths. CSC 331: Algorithm Analysis NP-Complete Problems

  34. Reduction Example Lpath(G, a, b, k) is a decision problem – is there a simple path from a to b in G of length at least k? Suppose that I want to know if a Hamiltonian Path exists in G. Let k be the number of nodes in G. Lpath(G,a,b,k) solves the Hamiltonian Path problem. CSC 331: Algorithm Analysis NP-Complete Problems

  35. Reduction Exercise Examination Scheduling Given a list of courses, a list of conflicts between them, and an integer k; is there an exam schedule consisting of k dates such that there are no conflicts between courses which have examinations on the same date? CSC 331: Algorithm Analysis NP-Complete Problems

  36. Reduction Exercise Examination Scheduling Given a list of courses, a list of conflicts between them, and an integer k; is there an exam schedule consisting of k dates such that there are no conflicts between courses which have examinations on the same date? Hint: Use graph coloring CSC 331: Algorithm Analysis NP-Complete Problems

  37. King Arthur’s Dinner • King Arthur invites his knights to dinner, but some of the • knights are arguing. King Arthur wants to sit the knights all around the round table, but he would like not to sit arguing knights next to each other. • He would like you to write a program that would tell whether or not there is a way to sit all the knights around the table without seating arguing knights next to each other. • How can you solve the problem? • Prove the solution is NP-Complete. CSC 331: Algorithm Analysis NP-Complete Problems

More Related