260 likes | 274 Views
Lecture 22. Hard Problems Introduction to NP. Key Words. Decision problem Optimization problem Non-deterministic algorithm NP-hard problem NP-complete problem Intractable problems Inherently difficult problems. Traveling Salesman Problem. Given : weighted complete graph G=(V,E,W)
E N D
Lecture 22 Hard Problems Introduction to NP
Key Words • Decision problem • Optimization problem • Non-deterministic algorithm • NP-hard problem • NP-complete problem • Intractable problems • Inherently difficult problems
Traveling Salesman Problem • Given: weighted complete graph G=(V,E,W) • Tour: visits all vertices exactly once • Cost of the tour: sum of weights of traversed edges • Optimization Problem: Find Optimal (Min Cost) Tour • Decision Problem: given a value w. Is there a tour of weight < w?
0-1 Knapsack Problem • Given: n items weighting w1, w2, …, wn lbs valued at p1, p2, …, pn $’s a knapsack of capacity W • Optimization Problem: Find maximum total of profit of items that can be placed in the knapsack • Decision Problem: Given also a profit P Find if there is a set of items of total weight <W with profit >P
Graph Coloring Problem • Given: a graph G=(V,E) • Coloring of G: coloring of vertices so that adjacent vertices get different colors • Optimization Problem: Find a coloring of G with minimum number of colors • Decision Problem: given a number k of colors. Is there a coloring with < k colors?
Clique Problem • Given: a graph G=(V,E) • Clique: complete subgraph • Optimization Problem: Find the largest clique • Decision Problem: given a number k. Is there a clique of size >= k colors?
Hamilton Cycle Problem • Given: a graph G=(V,E) • Hamilton Cycle: a cycle visiting every vertex exactly once (without repetitions) • Decision Problem: Is there a Hamilton cycle?
Traveling Salesman Problem • Given: weighted complete graph G=(V,E,W) • Tour: visits all vertices exactly once • Cost of the tour: sum of weights of traversed edges • Optimization Problem: Find Optimal (Min Cost) Tour • Decision Problem: given a value w. Is there a tour of weight < w?
Circuit Satisfiability • Logic gates: AND, OR, NOT • See how they operate: http://www.thefrog.com/javascript/boxes/ • Given: a circuit built up with logic gates, with n inputs x1, x2, … , xn and one output • The circuit is satisfied for some input values of 0/1 associated to x1, x2, … , xn if output of the circuit is 1. • Decision Problem: is there an assignment of 0/1 values to x1, x2, … , xn so that the circuit is satisfied?
Formula Satisfiability • Logic operators: AND, OR, NOT • Variables: x1, x2, … , xn • Boolean formula: ((x1 AND x2) OR (NOT x3 )) • Given: a boolean formula F with n variables x1, x2, … , xn • The formula is satisfied for some input values of 0/1 associated to x1, x2, … , xn if it evaluates to 1. • Decision Problem: is there an assignment of 0/1 values to x1, x2, … , xn so that the formula F is satisfied?
CNF Formula Satisfiability • CNF= Conjunctive Normal Form: conjunction of disjunctions ((.. OR..) AND (.. OR..) AND (..)) • AND: conjunction • OR: disjunction • Boolean formula: ((x1 AND x2) OR (NOT x3 )) • Given: a boolean formula F in CNF with n variables x1, x2, … , xn • Decision Problem: is there an assignment of 0/1 values to x1, x2, … , xn so that the CNF formula F is satisfied?
3SAT: Satisfiability of CNF Formulas with 3 literals per disjunction • Instance of 3SAT: ( (NOT x1) AND x2 AND x3) OR (x1 AND x3 AND x4) ) • Given: a boolean formula F in CNF with n variables x1, x2, … , xn, with 3 literacls per clause • Decision Problem: is there an assignment of 0/1 values to x1, x2, … , xn so that the formula F is satisfied?
Hardness of these Problems • None of the problems presented before is known to have a polynomial time algorithm • But they all have a common property: that if a solution is given, it is easy to verify it
Verification Problems • Given a decision problem: Does there exist x such that a property holds? • Verification Problem: given an object y, claimed to be a solution to the decision problem, verify that it is indeed the case
Examples • Verify that a tour is a TSP tour of weight < w • Verify that a given coloring with k colors is valid • Verify that a given complete subset of k vertices is a clique of G • Verify that a certain assignment of 0/1 values satisfies a boolean circuit/formula • Verify that a certain subset of items fits into a knapsack and has profit larger than P
It is easy to see that the VERIFICATION PROBLEM for • Traveling Salesman Problem • 0-1Knapsack • Graph Coloring • Clique • Circuit Satisfiability • Hamilton Tour is in P (can be done in polynomial time)
General “algorithm” for such problems: • Guess a candidate for a solution • Verify if it is a solution • If you are lucky, you’re done • Else you might have to generate all possible candidate solutions to find one, or say that none exists
Relating the Decision Problem to the Verification Problem TSP: is there …. so that … “a tour”: object can be described in polynomial space “it has a weight < w”: property can be verified in polynomial time
Complexity Class NP Class of all decision problems that can be described as: is there ….(a candidate solution describable in polynomial space) so that … (property that can be verified in polynomial time holds)? NP= nondeterministic polynomial time
What if ? • TRUE: then all the previously listed problems would have polynomial time algorithms • FALSE: one should stop looking for polynomial time algorithms for these problems, since none would exist (deep theorem, due to S. Cook – done in 353 Complexity Theory). This would imply a lower bound on the complexity of all of these problems.
NP-complete problems • If you proved that there is no polynomial time algorithm for any of them, you proved that there is no polynomial time algorithm for all the problems in NP • If you proved there exists a polynomial time algorithm for any of them, then you proved there is a polynomial time algorithm for all of the problems in NP.
NP-Complete Problems • TSP • Hamilton Cycle • Graph Coloring • 0-1 Knapsack • CNF Formula Satisfiability, etc are as HARD as any other problem in NP