NP-Complete Problems and Approximation Algorithms Efficiency of Algorithms Algorithms that have time efficiency of O(n k ), that is polynomial of the input size, are considered to be tractable or easy Those that require more time or can t be solved are considered to be intractable or hard Then there are problems for which a polynomial time solution is not known these are called NP-Complete problems Only a slight change in problems may have a polynomial time solution, but the problems themselves are not known to have 2
Example Finding the shortest path from a source to a destination in a directed graph has a polynomial time solution Finding the longest simple path between two vertices is NP-Complete. Even finding if a graph contains a simple path with at least a given number of edges is NP- Complete. 3 Class of Problems P - solvable in polynomial time NP - Verifiable in polynomial time. Given a certificate of solution, you can verify in polynomial time if that is correct. NP-Complete - No known polynomial time solution. It is as hard as any problem in NP NP-hard At least as hard as the hardest problem in NP There is a NP-Complete problem that is reducible to it The problem itself does not have to belong to NP 4
Why is it important? If you re looking for a solution to a problem, if you can show that the problem is NP-complete, you would rather look for an approximation algorithm or settle for an easier special case. 5 How to show NP-Complete Often applies to decision problems where you re looking for a yes/no (or) 1/0 solution Though not directly related to optimization problems, you may cast it as one and prove/disprove about the hardness of one and relate to the other 6
How to show NP-Complete Apply reductions Suppose you can show that an instance (sample input) of a problem can be transformed into an instance of another problem for which polynomial solution is known If you can do the transformation in polynomial time If you can show that the answer to the two problems are same for respective given instances You can use such a polynomial-time reduction algorithm to solve problem A in polynomial time 7 How to show NP-Complete Apply reductions For a problem with no known polynomial time solution, using polynomial time reduction to a NP- Complete problem, we can show the first problem is NP-Complete as well the proof here is based on the assumption that the second problem is NP-Complete. 8
Polynomial Time Problems with solution in polynomial time are considered tractable. Even if the order is high to being with, there are hopes of finding more efficient solutions Problems solvable in polynomial time on one model of a machine can be solved in polynomial time on other models as well Composition of polynomial time algorithms leads to polynomial time algorithms 9 Example of NP-Complete Circuit satisfiability problem If an electronic circuit will produce an output of 1, it is said to be satisfiable. If it always produces an output of 0 for any given input, it might as well be removed Determining the satisfiability of an electronic circuit is NP-Complete If you have k inputs to the overall circuit, there are 2 k combinations to check There is no known algorithm that s faster than!(2 k ) 10
Classes of Problems If a problem can be reduced to one of the known NP- Complete problem (and not to a problem with polynomial time) in polynomial time, then you can show that that problem is NP-Complete as well. Several problems can be reduced to the circuit satisfiability problem: Vertex-Cover Hamiltonian cycle Traveling Salesman Problem... 11 Approximation Algorithms While significant problems may not be entirely solvable in polynomial time, things are not totally hopeless You may find the time not prohibitively high for smaller input size You may modify the problem slightly to a meaningful special case and get a polynomial time solution You may find near-optimal solutions in polynomial time these are known as approximation algorithms 12
Approximation Ratio A problem has an approximation ratio of ρ(n), if for any input of size n, the cost C of the solution produced is within a factor of ρ(n) of the cost C * of an optimal solution: max (C/C*, C * /C) <= ρ(n) Such an algorithm is called ρ(n)-approximation algorithm For a minimization problem, the cost may be higher, for maximization problem, the cost may be lower, than the optimal solution The ratio is 1 at the best. An algorithm with lower ratio is better than one with higher ratio 13 Approximation Scheme For a fixed ε, the scheme is a (1 + ε)-approximation algorithm. An approximation scheme is a polynomial-time approximation scheme if for any fixed ε>0, the scheme runs in time polynomial in the size of its input instance. As ε decreases, the time can increase rapidly. Fully polynomial-time approximation schemes have runtime polynomial in both 1/ε and the size n of the input instance, for example O((1/ε) 2 n 3 ) Ideally, a constant factor decrease in ε should result in only (some other) constant factor increase in time 14
Vertex-cover Problem A vertex cover of an undirected graph G= (V,E) is a subset V V such that if (u, v) E, then u V or v V or both. The vertex-cover has vertices that cover all the edges of the original graph In other words, at least one vertex belonging to each edge in V is represented in V 15 Vertex-cover Problem Optimal vertex cover is a minimum size in a given undirected graph Approximation algorithm to get vertex-cover with no more than twice the size of an optimal vertex-cover Runtime O(V+E), polynomial 2-approximation algorithm Approx-Vertex-Cover(G) C <- E = G.E while E " let (u,v) be an arbitrary edge of E C -< C {u, v} remove from E every edge incident on either u or v return C 16
Traveling Salesman Problem NP-Complete You could apply triangle inequality for all vertices, where cost of travel C(u,w) <= C(u, v) + C(v, w) 2-approximation algorithm (no more than twice the cost) with O(V 2 ) time Approx-TSP-Tour(G, c) Select a vertex r G.V to be a root vertex Compute a minimum spanning tree T for G from root r let H be a list of vertices, ordered according to when they are first visited in a pre-order tree walk of T return the hamiltonian cycle H 17 The Set-cover Problem Generalizes the NP-Complete vertex-cover problem NP-hard As size of instance gets larger, size of approximation algorithm grows But growth is logarithmic, so not too bad 18
The Set-cover Problem Given: a finite set X and a family F of subset of X such that every element of X belongs to at least one subset of F Find a minimum size subset E F whose members cover all of X: X = S E S Sample application: Select a minimum size committee among people with varying skills so each skill is represented in the committee 19 Greedy Approx. Algorithm Greedy-Set-Cover(X, F) U <- X E <- while U " select an S F that maximizes S U U <- U - S E <- E {S} O( X F min( X, F )) p(n) approximation algorithm where p(n) = H(max{ S : S F}) H d = #i= 1 to d 1/i if the d th Harmonic number, and H(d) represents H d 20