cpsc 320 np completeness
play

CPSC 320: NP-Completeness CPSC 320 2013W2 CPSC 320: - PowerPoint PPT Presentation

CPSC 320: NP-Completeness CPSC 320 2013W2 CPSC 320: NP-Completeness Up to now: We have been learning recipes to design efficient algorithms. Every problem we looked at can be solved in O(n), or O(n log n), or O(n 2 ), or maybe O(n 3


  1. CPSC 320: NP-Completeness CPSC 320 – 2013W2

  2. CPSC 320: NP-Completeness Up to now: We have been learning “recipes” to design efficient algorithms. Every problem we looked at can be solved in O(n), or O(n log n), or O(n 2 ), or maybe O(n 3 ). In this sense, every one of these problems was easy to solve. Definition : a problem is solvable in polynomial time if there is an algorithm for it that runs in O(n k ) time for some integer k ≥ 0. CPSC 320 – 2013W2

  3. CPSC 320: NP-Completeness Now: We will look at problems that (we think) are hard to solve. It doesn't mean the problems are difficult to describe. Only that we don't know of any efficient algorithms for them. CPSC 320 – 2013W2

  4. CPSC 320: NP-Completeness Examples: Find a way to schedule n exams in k time-slots without any exam hardship. Find the cheapest route for a traveling business person to visit n cities and come back to his/her starting point. Find k students, in a class of size n, that (already) all know one another. Divide a group of n people into two teams of equal total strength to play tug-of-war. CPSC 320 – 2013W2

  5. CPSC 320: NP-Completeness Two types of problems: Optimization problem: we want to find the solution s that maximizes or minimizes a function f(s). Decision problem: we are given a parameter k, and we need to decide if there is a solution s for which f(s) ≤ k [minimization] or f(s) ≥ k [maximization]. So the answer is True or False . CPSC 320 – 2013W2

  6. CPSC 320: NP-Completeness Problem 1: Clique Definition : Given a graph G = (V, E), a clique of G is a subset V' of V such that every two vertices of V' are joined by an edge in G. Optimization Problem : Given G = (V, E), find the largest clique of G. Decision Problem : Given G = (V, E) and an integer k, does G have a clique with at least k vertices? CPSC 320 – 2013W2

  7. CPSC 320: NP-Completeness The two types of problem are very similar in terms of complexity: If we have a solution to the optimization problem, then it gives us an answer to the decision problem. If we can solve the decision problem efficiently, then we can use binary search on k to find the answer to the optimization problem. We will look at decision problems only. CPSC 320 – 2013W2

  8. CPSC 320: NP-Completeness Problem 2: Satisfiability (SAT) Given A set of boolean variables X 1 , X 2 , ..., X n . A set of clauses C 1 , C 2 , ..., C m where for each i, C i = Y i,1 ν Y i,2 ν ... ν Y i,ti where each Y i,j is either X k or ~X k . We want to know if there is a way to set each X k to true or false, so that every clause evaluates to true. CPSC 320 – 2013W2

  9. CPSC 320: NP-Completeness Problem 3: 3-Satisfiability (3SAT) The same, but every clause contains exactly three variables (or complements of variables). Example: C 1 : X 1 v X 3 v ~X 4 C 2 : ~X 1 v X 2 v X 4 C 3 : X 2 v ~X 3 v ~X 4 C 4 : ~X 1 v ~X 2 v ~X 3 CPSC 320 – 2013W2

  10. CPSC 320: NP-Completeness Problem 4: Graph k-colourability Given: a graph G = (V, E) and a positive integer k. We want to know if it is possible to colour every vertex with one of k different colors so that no edge has both its endpoints with the same color. CPSC 320 – 2013W2

  11. CPSC 320: NP-Completeness This problem has many practical applications, for instance exam scheduling: Each vertex is a course. An edge means a student is taking both courses. Each colour represents a time-slot. An edge with two endpoints of the same colour means an exam conflict for one or more students! CPSC 320 – 2013W2

  12. CPSC 320: NP-Completeness Now we can get to the heart of the topic: we look at two sets: P : the set of all problems that can be solved in polynomial time. NP : the set of all problems such that, if the answer is true, then there is a “proof” of that fact that can be verified in polynomial time. CPSC 320 – 2013W2

  13. CPSC 320: NP-Completeness Examples: For SAT or 3SAT: The proof is an assignment of true/false values to the variables. We can verify that all clauses are satisfied fairly quickly. For Graph k-colorability: The proof is the colour assigned to each vertex. We can count the different colours and verify there are at most k of them. We can verify that every edge has endpoints of different colours. CPSC 320 – 2013W2

  14. CPSC 320: NP-Completeness Is P = NP ? Nobody knows Most people think the answer is No . CPSC 320 – 2013W2

  15. CPSC 320: NP-Completeness We have Easy problems. Problems that we think are hard. Cook's theorem : if SAT can be solved in polynomial time, then every problem in NP can be solved in polynomial time. A problem that belongs to NP and has this property is called NP-complete. Why do we want to know if a problem is NP-complete? CPSC 320 – 2013W2

  16. CPSC 320: NP-Completeness Suppose your boss asked you to design an algorithm to solve a problem. You would like to avoid this: Illustration taken from Garey & Johnson, page 2 CPSC 320 – 2013W2

  17. CPSC 320: NP-Completeness Ideally, you would like to do this: Illustration taken from Garey & Johnson, page 2 CPSC 320 – 2013W2

  18. CPSC 320: NP-Completeness But since you can't (we still don't know if P = NP ), at least you might be able to do this, and avoid getting fired: Illustration taken from Garey & Johnson, page 3 CPSC 320 – 2013W2

  19. CPSC 320: NP-Completeness How do we prove that a problem P is NP-Complete? First we prove that P belongs to NP . This is (usually) easy: Show what kind of “proof” for Yes answers can be checked in polynomial time. CPSC 320 – 2013W2

  20. CPSC 320: NP-Completeness How do we prove that a problem P is NP-Complete (continued)? Then we prove that if we can solve P in polynomial time, then every other problem in NP can be solved in polynomial time. This is (usually) a bit more involved. The proof of Cook's theorem is ugly (6 pages in Garey & Johnson). Luckily, now that we know that SAT is NP-complete, we can use a much simpler method. CPSC 320 – 2013W2

  21. CPSC 320: NP-Completeness Polynomial-time reduction: Pick a known NP-complete problem P NPC . Give a polynomial-time algorithm that transforms instances of P NPC into instances of P with the same Yes/No answer. Instance of P NPC Instance of P Transformation (poly-time) CPSC 320 – 2013W2

  22. CPSC 320: NP-Completeness If you could solve P efficiently, then you could solve an instance of P NPC as follows: Transform it into an instance of P . Solve the instance of P and return the same answer. Since P NPC is NP-complete, this means you could solve every problem in NP in polynomial time! CPSC 320 – 2013W2

  23. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete: Clearly 3SAT is in NP: the proof for a Yes answer is the values we need to give the variables. We can verify that every variable is assigned exactly one value, and that every clause evaluates to true. CPSC 320 – 2013W2

  24. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete: Now we show every instance I of SAT can be transformed into an instance I' of 3SAT. Consider a clause C. If C contains exactly three variables, then we copy C to I'. If C is Y 1 v Y 2 , then we add two clauses Y 1 v Y 2 v Z Y 1 v Y 2 v ~Z to I' where Z is a new variable. Observe that Y 1 v Y 2 is true if and only if both these clauses are true (no matter what value we give Z). CPSC 320 – 2013W2

  25. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete: Consider a clause C (continued): If C is Y, then we add four clauses Y v Z 1 v Z 2 Y 1 v Z 1 v ~Z 2 Y 1 v ~Z 1 v Z 2 Y 1 v ~Z 1 v ~Z 2 to I'. Observe that Y is true if and only if all four clauses are true, no matter what values we give Z 1 and Z 2 . CPSC 320 – 2013W2

  26. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete (continued): Consider a clause C (continued): If C contains more than 3 variables, we proceed as in the following example. Suppose C = Y 1 v Y 2 v Y 3 v Y 4 v Y 5 v Y 6 v Y 7 . Then we add the following to I': Y 1 v Y 2 v Z 1 ~Z 1 v Y 3 v Z 2 ~Z 2 v Y 4 v Z 3 ~Z 3 v Y 5 v Z 4 ~Z 4 v Y 6 v Y 7 CPSC 320 – 2013W2

  27. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete (continued): If all the Y's are false, then how could we satisfy all 5 clauses? Y 1 v Y 2 is false, so Z 1 must be true. ~Z 1 v Y 3 is false, so Z 2 must be true. ... ~Z 3 v Y 5 is false, so Z 4 must be true. But then ~Z 4 v Y 6 v Y 7 is false. So we can not satisfy all five clauses if all the Y's are false. CPSC 320 – 2013W2

  28. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete (continued): If Y j is true then we can make all the clauses true by setting Z k true for k < j-1, and false for k ≥ j-1. For instance, suppose Y 4 is true: the red term in each clause is true (other terms might also be true if more than one Y is true). Y 1 v Y 2 v Z 1 ~Z 1 v Y 3 v Z 2 ~Z 2 v Y 4 v Z 3 ~Z 3 v Y 5 v Z 4 ~Z 4 v Y 6 v Y 7 CPSC 320 – 2013W2

  29. CPSC 320: NP-Completeness Example: proving that 3SAT is NP-Complete (continued): Therefore the answer to the instance I of SAT is “Yes” if and only if the answer to the instance I' of 3SAT is “Yes”. Moreover we can generate I' in linear time. CPSC 320 – 2013W2

Recommend


More recommend