Download presentation

Presentation is loading. Please wait.

Published bySonia Amberson Modified over 2 years ago

1
NP-hard problems and Approximation algorithms1 Lectures on NP-hard problems and Approximation algorithms COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski

2
NP-hard problems and Approximation algorithms2 Overview Previous lectures: Greedy algorithms Dynamic programming Network flows These lectures: NP-hard problems Approximation algorithms

3
NP-hard problems and Approximation algorithms3 P versus NP Decision problem: problem for which the answer must be either YES or NO Polynomial time algorithm: there is a constant c such that the algorithm solves the problem in time O(n c ) for every input of size n P (polynomial time) - class of decision problems for which there is a polynomial time deterministic algorithm solving the problem NP (nondeterministic polynomial time) - class of decision problems for which there is a certifier which can check a witness in polynomial time

4
NP-hard problems and Approximation algorithms4 Certifying in polynomial time Representation of decision problem: set of inputs which are correct (and should be answered YES, while others should be answered NO) An efficient certifier B for problem X: B is in P s is in X iff B(s,t) = YES for some t of size polynomial in s Example: Problem: is there a clique of size k in a given graph with n nodes? Certifier: if a given graph has a clique of size k then given this clique as the second parameter we can answer YES

5
NP-hard problems and Approximation algorithms5 Computing an efficient certifier How to compute witnesses for an efficient certifier for a given problem? Fact: If the witnesses for the efficient certifier can be found in polynomial time then the problem is in P. Conclusion: P is included in NP Open question: P = NP ?

6
NP-hard problems and Approximation algorithms6 Polynomial reductions Example: decision problem if there exists a perfect matching in a bipartite graph can be reduced to network flow problem in polynomial time (by adding source, target and directing the edges) Other problems for undirected graphs (in NP and not known to be in P): Independent Set of nodes Vertex cover Set Cover

7
NP-hard problems and Approximation algorithms7 Polynomial reductions Definition: Problem X is polynomial-time reducible to problem Y, or problem Y is at least as hard as problem X, iff problem X can be solved by an algorithm which works in polynomial time and uses polynomial number of calls to the black box solving problem Y. Notation: X P Y Transitivity Property: if X P Y and Y P Z then X P Z

8
NP-hard problems and Approximation algorithms8 Independent Set to Vertex Cover Independent Set: given a graph G of n nodes and parameter k, is there a set of k nodes such that none two of them are connected by an edge? Vertex Cover: given a graph G of n nodes and parameter k, is there a set of k nodes such that every edge has at least one end selected? Polynomial Reduction: Solve Vertex-Cover(n-k) for the same graph Proof: Set S of size n - k is a vertex cover set in G iff There is no edge between remaining k nodes iff Set of k remaining nodes is independent in G

9
NP-hard problems and Approximation algorithms9 Vertex Cover to Set Cover Vertex Cover: given a graph G of n nodes and parameter k, is there a set of k nodes such that every edge has at least one end among selected nodes? Set Cover: given n nodes, m sets which cover the set of nodes, and parameter k, is there a family of k sets that covers all n nodes? Polynomial Reduction: Let each edge from the graph correspond to the node for SC system For each vertex in the graph create a set of incident edges to SC system Solve Set-Cover(m,n,k) for the created SC system with m nodes and n sets Proof: Each node-edge is covered by at least one set-vertex since each node is covered. This covering is minimal.

10
NP-hard problems and Approximation algorithms10 NP-completeness and NP-hardness NP-complete: class of problems X such that every problem from NP is polynomial-time reducible to X. Optimization problems: problems where the answer is a number (maximum/minimum possible) Each optimization problem has its decision version, e.g., Find a maximum Independent Set Is there an Independent Set of size k? NP-hard: class of optimization problems X such that its decision version is NP-complete. Example: having solution for decision version of Independent Set problem, we can probe a parameter k, starting from k = 1, to find the size of the maximum independent set

11
NP-hard problems and Approximation algorithms11 Approximation algorithms Having an NP-hard problem, we do not know at this moment any polynomial-time algorithm solving the problem (exact solution) How to find an almost optimal solution? Approximation algorithm with ratio a > 1 gives a solution A such that OPT A a OPT for a min-optimization problems (1/a) OPT A OPT for a max-optimization problems where OPT is the optimal solution.

12
NP-hard problems and Approximation algorithms12 2-approximation for VC Minimum Vertex Cover - NP-hard problem (maximum is trivially n) Algorithm: Initialize set C to an empty set While there are remaining edges: Choose an edge {v,w} with the largest degree, where degree of an edge is a sum of degrees of its ends v,w in a current graph G Put v,w to C Remove all the edges adjacent to nodes v,w from graph G Output: witness set C and its size

13
NP-hard problems and Approximation algorithms13 Analysis of 2-approximation for VC Correctness: Each edge is removed only after one of its ends is chosen to set C, so each edge is covered Termination: In each iteration we remove at least one edge from the graph, and there are less than n 2 edges Approximation ratio 2: For each edge {v,w} selected at the beginning of an iteration at least one end must be in min-VC, and we selected two, so set C is at most twice bigger than the min-VC Time complexity: O(m + n) Exercise

14
NP-hard problems and Approximation algorithms14 Approximation for SC Minimum Set Cover - NP-hard problem (maximum is trivially m) Greedy Algorithm: Initialize set C to empty set While there are uncovered nodes: Choose a set F which covers the largest number of uncovered nodes Put F to C Remove all nodes covered by F Output: witness set C and its size

15
NP-hard problems and Approximation algorithms15 Analysis of approximation for SC Correctness: Each node is marked as covered when we put the set covering it to set C. The algorithm stops when all nodes are covered. Termination: In each iteration we cover at least one new node, and there are n nodes. Approximation ratio log n: Let S i be the set selected to C in i th iteration, and denote by s i the number of uncovered nodes covered by S i ; OPT be the minimum covering set Let c v = 1/ s i for each node v which was covered by S i for the first time The following holds: |C| = v c v For every set S = S i : v S c v H(|S|) (H(i)= j i 1/j denotes harmonic number) |C| = v c v S OPT v S c v H(n) S OPT 1 = H(n) |OPT| |OPT| log n Time and memory complexities: O(M + n), where M is the sum of cardinalities of sets Exercise

16
NP-hard problems and Approximation algorithms16 Conclusions Decision problems P and NP-complete –Polynomial-time reduction Optimization problems in NP-hard –Maximum Independent Set –Minimum Vertex Cover –Minimum Set Cover Approximation algorithms - polynomial time –Min-VC with ratio 2 –Min-SC with ratio log n

17
NP-hard problems and Approximation algorithms17 Textbook and Questions READING: Chapters 8 and 11, Sections 8.1, 8.2, 8.3, 11.3, 11.4 EXERCISES: What is the time and memory complexities of min-VC approximation algorithm with ratio 2 and min-SC algorithm? Consider a modification of min-VC algorithm: choose a node which covers the largest number of uncovered edges. Is it a 2- approximation algorithm? Having a 2-approximation algorithm for min-VC, is it easy to modify it to be a 2-approximation algorithm for max-IS (since there is a simple polynomial-time reduction between these two problems)?

18
NP-hard problems and Approximation algorithms18 Overview Previous lectures: NP-hard problems and approximation algorithms –Graph problems (IS, VC) –Set problem (SC) This lecture: NP-hard numerical problems and their approximation –Numerical Knapsack problem –Weighted Independent Set

19
NP-hard problems and Approximation algorithms19 Knapsack problem Input: set of n items, each represented by its weight w i and value v i ; thresholds W and V Decision problem: is there a set of items of total weight at most W and total value V ? Optimization problem: find a set of items with –total weight at most W, and –maximum possible value Assumptions: –weights and values are positive integers –each weight is at most W

20
NP-hard problems and Approximation algorithms20 NP-hardness of knapsack Knapsack is NP-hard problem, but there exists pseudo-polynomial algorithm (complexity is polynomial in terms of values) Typical numerical polynomial algorithm: polynomial in logarithm from the maximum values (longest representation) Existence of pseudo-polynomial solution often yields very good approximation schemes

21
NP-hard problems and Approximation algorithms21 Dynamic pseudo-polynomial optimization algorithm Let v* be the maximum (integer) value of an item. Consider any order of objects. Let OPT(i,v) denote the minimum possible total weight of a subset of items 1,2,…,i which has total value v Dynamic formula for i = 0,1,…,n-1 and v = 0,1,…,nv* : OPT(i+1,v) = = min{ OPT(i,v), w i+1 + OPT(i,max{0,v-v i+1 })} Formula OPT does not provide direct solution for our problem, but can be easily adapted: maximum value of knapsack is the maximum value v such that OPT(n,v) W

22
NP-hard problems and Approximation algorithms22 Dynamic algorithm Initialize array M[0…n,0…nv*] for storing OPT(i,v) Fill positions M[ ,0] and M[0, ] with zeros For i = 0,1,…,n-1 For v = 0,1,…,nv* M[i+1,v] := = min{ M[i,v], w i+1 + M[i,max{0,v-v i+1 }] } Go through the whole array M and find the maximum value v such that M[n,v] W

23
NP-hard problems and Approximation algorithms23 Complexities Time: O(n 2 v*) Initializing array M : O(n 2 v*) Iterating loop: O(n 2 v*) Searching for maximum v : O(n 2 v*) Memory: O(n 2 v*)

24
NP-hard problems and Approximation algorithms24 Polynomial approximation algorithm Algorithm: Fix b = ( /(2n)) v* Set (by rounding up) x i = [v i /b] Solve knapsack problem for values x i and weights w i using dynamic program Return set of computed items and its total value in terms of the sum of v i ’s

25
NP-hard problems and Approximation algorithms25 Analysis PTAS: polynomial time approximation scheme - for any fixed positive it produces (1+ )-approximation in polynomial time (but is hidden in big Oh) Time: O(n 2 x*) = O(n 3 / ) Approximation: (1+ )

26
NP-hard problems and Approximation algorithms26 Analysis of approximation ratio Recall notation: b = ( /(2n)) v* x i = [v i /b] Approximation: (1+ ) Let S denote the set of items returned by the algorithm v i bx i v i + b i S bx i - b|S| i S v i i S bx i v* = 2nb/ (2/ -1)nb i S v i i OPT v i i OPT bx i i S bx i b|S|+ i S (bx i - b) b(2/ -1)n + i S v i i S v i + i S v i = (1+ ) i S v i

27
NP-hard problems and Approximation algorithms27 Weighted Independent Set Optimization problem: Weighted Independent Set: given graph G of n valued nodes, find an independent set of maximum value (set of nodes such that none two of them are connected by an edge) Even for values 1 problem remains NP-hard, which is not the case for knapsack problem! WIS problem is an example of strong NP-hard problem, and no PTAS is known for it

28
NP-hard problems and Approximation algorithms28 Conclusions Optimization numerical problem in NP-hard –Maximum Knapsack –Weighted Independent Set PTAS in time O(n 3 ) for Knapsack, based on dynamic programming

29
NP-hard problems and Approximation algorithms29 Textbook and Questions Chapters 6 and 11, Sections 6.4, 11.8 Is it possible to design an efficient Knapsack algorithm based on dynamic programming for the case where weights are small (values can be arbitrarily large) How to implement arithmetical operations: + - * / and rounding, each in time proportional to at most square of the length of the longest number? What are the complexity formulas?

30
NP-hard problems and Approximation algorithms30 Overview Previous lectures: NP-hard problems Approximation algorithms –Greedy (VC and SC) –Dynamic Programming (Knapsack) This lecture: Approximation through integer programming

31
NP-hard problems and Approximation algorithms31 Vertex Cover Weighted Vertex Cover: (weights are in nodes) Decision problem: –given weighted graph G of n nodes and parameter k, –is there a set of nodes with total weight k such that every edge has at least one end in this set? Optimization problem: –given weighted graph G of n nodes, what is the minimum total weight of a set such that every edge has at least one end in this set?

32
NP-hard problems and Approximation algorithms32 Approximation algorithms Having an NP-hard problem, we do not know in this moment any polynomial-time algorithm solving the problem (exact solution) How to find almost optimal solution? Approximation algorithm with ratio a > 1 gives a solution A such that OPT A a OPT for a min-optimization problems OPT/a A OPT for a max-optimization problems where OPT is an optimal solution.

33
NP-hard problems and Approximation algorithms33 2-approximation for VC Minimum Vertex Cover - NP-hard problem even for all weights = 1 (maximum is trivially n) Algorithm: (for all weights equal to 1) Initialize set C to empty set While there are remaining edges: Choose an edge {v,w} (with the largest degree, where degree of an edge is a sum of degrees of its ends v,w in a current graph G ) Put v,w to C Remove all the edges adjacent to nodes v,w from graph G Output: witness set C and its size

34
NP-hard problems and Approximation algorithms34 Integer Programming Represent the problem as Integer Programming Relax the problem to Linear Programming Solve Linear Programming Round the solution to get integers

35
NP-hard problems and Approximation algorithms35 Integer and linear programs Set of constraints (linear equations): x 1, x 2 0 x 1 + 2x 2 6 2x 1 + x 2 6 Function to minimize (linear): 4x 1 + 3x 2 Linear programming: –variables are real numbers –there are polynomial time algorithms solving it (e.g., interior point method - by N. Karmarkar in 1984); simplex method is not polynomial Integer programming: –variables are integers –problem is NP-hard

36
NP-hard problems and Approximation algorithms36 VC as Integer Program Set of constraints : x i {0,1} for every node i x i + x j 1 for every pair {i,j} E Function to minimize: i x i w i Example: x 1, x 2, x 3, x 4 {0,1} x 1 + x 3 1, x 1 + x 4 1, x 2 + x 4 1, x 2 + x 3 1 Minimize: x 1 + x 2 + x 3 + x 4 x1x1 x2x2 x3x3 x4x4

37
NP-hard problems and Approximation algorithms37 Relaxation to Linear Program Set of constraints : y i [0,1] for every node i y i + y j 1 for every pair {i,j} E Function to minimize: i y i w i Example: y 1, y 2, y 3, y 4 [0,1] y 1 + y 3 1, y 1 + y 4 1, y 2 + y 4 1, y 2 + y 3 1 Minimize: y 1 + y 2 + y 3 + y 4 y1y1 y2y2 y3y3 y4y4

38
NP-hard problems and Approximation algorithms38 Rounding the linear program solution Obtained exact Linear Program solution y i [0,1] for every node i satisfying y i + y j 1 for every pair {i,j} E How to obtain a (approximate?) solution for Integer Program? Rounding: for every node i x i = 1 iff y i 1/2 (otherwise x i = 0) Example: y 1, y 2, y 3, y 4 = 1/2 x 1, x 2, x 3, x 4 = 1 Optimum solution (minimum) e.g.: x 1, x 2 = 1, x 3, x 4 = 0 x1x1 x2x2 x3x3 x4x4

39
NP-hard problems and Approximation algorithms39 Analysis Correctness: since each x i {0,1} and each edge is guarded by constraint x i + x j 1 which is satisfied also after rounding Time: time for solving linear program plus O(m+n) Approximation: Each x i is at most twice as large as y i hence the weighted sum of x i is also at most twice bigger than the weighted sum of y i Example: y 1, y 2, y 3, y 4 = 1/2 x 1, x 2, x 3, x 4 = 1 Optimum solution (minimum) e.g.: x 1, x 2 = 1, x 3, x 4 = 0 x1x1 x2x2 x3x3 x4x4

40
NP-hard problems and Approximation algorithms40 Conclusions Decision problems P and NP-complete –Polynomial-time reduction Optimization problems in NP-hard –Maximum Independent Set –Minimum Vertex Cover –Minimum Set Cover –Maximum Knapsack Approximation algorithms - polynomial time –Greedy (VC, SC) –Dynamic program (Knapsack) –Integer and Linear programs (weighted VC)

41
NP-hard problems and Approximation algorithms41 Textbook and Questions READING: Chapter 11, Section 11.6 EXERCISES: Could we solve Weighted VC by modification of greedy algorithm solving (pure) VC? What approximation we get if we apply randomized rounding, i.e., x i = 1 with probability y j (otherwise x i = 0) Traveling Salesman Problem : Section 8.5 TSP can not be approximated with a constant unless P=NP Constant approximation of TSP problem under the assumption that the weights satisfy metric conditions (symmetric weights satisfying triangle inequality)

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google