Analysis of Algorithms Approximation Algorithms Lecture 27 1 Topic Computer Science response to the phenomenon of NP-Completeness Algorithms that approximate the solution of NP-complete problems. 2 Vertex Cover to Dominating Set Create a new graph such that there exists a vertex for each vertex in G. Furthermore, add a new vertex for each edge in 𝐺, such that there now exists a triangle of edges. That is to say, for an edge, 𝑒 = (𝑢,𝑣) there now exists a new vertex, 𝑧 , and the edges (𝑢,𝑣), (𝑢,𝑧), (𝑣,𝑧). We have to prove that our graph 𝐺 has a vertex cover of size 𝑘 iff the new graph has a dominating set of size 𝑘. If we have a set, 𝑆, that is a vertex cover of 𝐺, then we know that the same set is a dominating set on the new graph. By definition of vertex cover, each edge in 𝐺 is incident to at least one vertex in 𝑆. Therefore, each triangle of vertices in the new graph has at least one member of which belongs to 𝑆. As a result, we know that each vertex in the new graph is either in 𝑆 or adjacent to 𝑆, which is the definition of a dominating set. 3 Motivation By now we’ve seen many NP-Complete problems. We conjecture none of them has polynomial time algorithm. Unfortunately, many of the problems in NP are of great practical use. Motivates search for good approximation algorithms 4 Optimization Many of the problems we’ve encountered so far are really optimization problems. I.e - the task can be naturally rephrased as finding a maximal/minimal solution. For example: finding a maximal clique in a graph. 5 Approximation An algorithm that returns an answer 𝐶 which is “close” to the optimal solution 𝐶 ∗ is called an approximation algorithm. “Closeness” is usually measured by the ratio bound (𝑛) the algorithm produces. Which is a function that satisfies, for any input size 𝑛, max 𝐶 𝐶∗ , 𝐶∗ 𝐶 (𝑛). 6 Vertex-Cover Instance: an undirected graph 𝐺 = (𝑉, 𝐸). Problem: find a set 𝐶 ⊆ 𝑉 of minimal size s.t. for any (𝑢, 𝑣) ∈ 𝐸, either 𝑢 ∈ 𝐶 or 𝑣 ∈ 𝐶. 7 Network Power A network, with links between some components Each link requires power supply, hence, you need to supply power to a set of nodes that cover all links Obviously, you’d like to connect the smallest number of nodes 8 VC - Approximation Algorithm C E’ E while E’ do let (u,v) be an arbitrary edge of E’ C C {u,v} remove from E’ every edge incident to either u or v. return C. 9 Trace 10 Polynomial Time – Asymptotic Complexity C E’ E O(n ) while E’ do let (u,v) be an arbitrary edge of E’ C C {u,v} Remove from E’ every edge incident to either u or v return C 2 11 Quality of Approximations Four examples 12 Correctness and Quality The set of vertices our algorithm returns is clearly a vertex-cover, since we iterate until every edge is covered Approximation has no more than twice the nodes in the optimal cover 13 Mass Mailing Wish to send some message to a large list of people (e.g. all campus) There are some available mailing-lists, however, the moderator of each list charges $1 for each message sent You’d like to find the smallest set of lists that covers all recipients 14 Set-Cover Instance: a finite set 𝑋 and a family 𝐹 of subsets of 𝑋, such that 𝑋 = 𝑆∈𝐹 𝑆 Problem: to find a set 𝐶 ⊆ 𝐹 of minimal size which covers 𝑋, i.e – 𝑋= 𝑆 𝑆∈𝐶 15 Set-Cover: Example 16 Demonstration 17 Set-Cover is NP-Hard Proof: Observe the corresponding decision problem. Can reduce Vertex-Cover to set Cover? 18 VERTEX-COVER p SET-COVER One element for every edge SC VC VC One set for every vertex, containing the edges it covers 19 Set Cover - A Greedy Algorithm 𝐶 𝑈 𝑋 // Make a copy of the sets while 𝑈 do Select 𝑆𝐹 that maximizes |𝑆 ∩ 𝑈| 𝐶 𝐶 {𝑆} 𝑈𝑈 − 𝑆 return C We can bound the approximation by log 𝑛 There is a tight bound at ln 𝑛 20 The Trick We’d like to compare the number of subsets returned by the greedy algorithm to the optimal The optimal is unknown, however, if it consists of 𝑘 subsets, then any part of the universe can be covered by 𝑘 subsets! 21 Reasoning Claim: If there is a cover of size 𝑘, then after 𝑘 iterations the algorithm has covered at least ½ of the elements 22 Approximating Traveling Salesman Approx-TSP-Tour ( 𝐺, 𝑐 ) Select a vertex 𝑟 ∈ 𝐺. 𝑉 to be a “root” vertex Computer minimum spanning tree 𝑇 for 𝐺 from 𝑟 Using Prim’s algorithm (𝐺, 𝑐, 𝑟) Let 𝐻 be a list of vertices, ordered according to when they are fist visited in a preorder tree walk of 𝑇 Return the Hamiltonian cycle 𝐻 23 Approximating Traveling Salesman Approx-TSP-Tour ( 𝐺, 𝑐 ) Select a vertex 𝑟 ∈ 𝐺. 𝑉 to be a “root” vertex Computer minimum spanning tree 𝑇 for 𝐺 from 𝑟 Using Prim’s algorithm (𝐺, 𝑐, 𝑟) Let 𝐻 be a list of vertices, ordered according to when they are fist visited in a preorder tree walk of 𝑇 Return the Hamiltonian cycle 𝐻 24 Approximating Traveling Salesman Minimum spanning tree: In-order traversal Visit self Visit left-subtree Visit right-subtree Resulting Hamiltonian cycle: cost 19.074 Optimal tour: cost 14.715 25 Summary Can sometimes find efficient approximation algorithms for NPhard problems. We’ve seen two such algorithms: for VERTEX-COVER (factor of 2) for SET-COVER (logarithmic factor). 26 Populating the NP-Completeness Universe NP-Complete Circuit Sat <P 3-SAT 3-SAT <P Independent Set 3-SAT <P Vertex Cover Independent Set <P Clique NP 3-SAT <P Hamiltonian Circuit P Hamiltonian Circuit <P Traveling Salesman 3-SAT <P Integer Linear Programming 3-SAT <P Graph Coloring 3-SAT <P Subset Sum Subset Sum <P Scheduling with Release times and deadlines 27 Open Questions Does every NP-hard problem have an approximation? And to within which factor? 28 ְׁש ִליחָ ה Envoi 傳送中 ְׁש ִליחָ ה This concludes Lecture 27 There is an exercise to be submitted by the end of the day 29