Algorithms Design & Analysis. Approximation Algorithm

Similar documents
NP and Computational Intractability

COP 4531 Complexity & Analysis of Data Structures & Algorithms

8.1 Polynomial-Time Reductions. Chapter 8. NP and Computational Intractability. Classify Problems

Algorithm Design and Analysis

Polynomial-Time Reductions

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

4/19/11. NP and NP completeness. Decision Problems. Definition of P. Certifiers and Certificates: COMPOSITES

4/22/12. NP and NP completeness. Efficient Certification. Decision Problems. Definition of P

Chapter 8. NP and Computational Intractability. CS 350 Winter 2018

Approximation and Randomized Algorithms (ARA) Lecture 2, September 1, 2010

Computational Intractability 2010/4/15. Lecture 2

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

Algorithm Design and Analysis

Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

3/22/2018. CS 580: Algorithm Design and Analysis. 8.3 Definition of NP. Chapter 8. NP and Computational Intractability. Decision Problems.

Intro to Theory of Computation

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

Lecture 4: NP and computational intractability

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Intro to Theory of Computation

NP and Computational Intractability

1. Introduction Recap

SAT, Coloring, Hamiltonian Cycle, TSP

ECS122A Handout on NP-Completeness March 12, 2018

CS 580: Algorithm Design and Analysis

3/22/2018. CS 580: Algorithm Design and Analysis. Circuit Satisfiability. Recap. The "First" NP-Complete Problem. Example.

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

NP-Complete Problems. More reductions

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

Announcements. Analysis of Algorithms

7.8 Intractability. Overview. Properties of Algorithms. Exponential Growth. Q. What is an algorithm? A. Definition formalized using Turing machines.

8.5 Sequencing Problems

Design and Analysis of Algorithms

NP completeness and computational tractability Part II

VIII. NP-completeness

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

Computability and Complexity

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

Polynomial-time reductions. We have seen several reductions:

NP Completeness and Approximation Algorithms

NP and NP-Completeness

NP-completeness. Chapter 34. Sergey Bereg

P and NP. Inge Li Gørtz. Thank you to Kevin Wayne, Philip Bille and Paul Fischer for inspiration to slides

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

NP Complete Problems. COMP 215 Lecture 20

P and NP. Warm Up: Super Hard Problems. Overview. Problem Classification. Tools for classifying problems according to relative hardness.

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

NP-Complete Problems and Approximation Algorithms

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

NP-Completeness. Until now we have been designing algorithms for specific problems

Tractable & Intractable Problems

COMP Analysis of Algorithms & Data Structures

7.8: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

Limitations of Algorithm Power

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

NP-Complete Reductions 1

Algorithms: COMP3121/3821/9101/9801

Topics in Complexity Theory

Correctness of Dijkstra s algorithm

NP-Completeness. Subhash Suri. May 15, 2018

10.3: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

Chapter 34: NP-Completeness

Graduate Algorithms CS F-21 NP & Approximation Algorithms

P, NP, NP-Complete, and NPhard

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Tractability. Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time?

NP-Completeness. ch34 Hewett. Problem. Tractable Intractable Non-computable computationally infeasible super poly-time alg. sol. E.g.

8.5 Sequencing Problems. Chapter 8. NP and Computational Intractability. Hamiltonian Cycle. Hamiltonian Cycle

NP-Completeness. NP-Completeness 1

More NP-Complete Problems

Complexity Theory Part II

Chapter 8. NP and Computational Intractability

Limits to Approximability: When Algorithms Won't Help You. Note: Contents of today s lecture won t be on the exam

Computability and Complexity Theory: An Introduction

CS 580: Algorithm Design and Analysis

Automata Theory CS Complexity Theory I: Polynomial Time

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

ABHELSINKI UNIVERSITY OF TECHNOLOGY

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

Algorithms 6.5 REDUCTIONS. designing algorithms establishing lower bounds classifying problems intractability

July 18, Approximation Algorithms (Travelling Salesman Problem)

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

Unit 1A: Computational Complexity

Computational Complexity

Data Structures in Java

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

1.1 P, NP, and NP-complete

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

CS/COE

Approximation Algorithms

4/20/11. NP-complete problems. A variety of NP-complete problems. Hamiltonian Cycle. Hamiltonian Cycle. Directed Hamiltonian Cycle

Transcription:

Algorithms Design & Analysis Approximation Algorithm

Recap External memory model Merge sort Distribution sort 2

Today s Topics Hard problem Approximation algorithms Metric traveling salesman problem A load balancing problem Inapproximability 3

Classify Problems Desiderata. Classify problems according to those that can be solved in polynomial-time and those that cannot. Provably requires exponential-time. Given a Turing machine, does it halt in at most k steps? Given a board position in an n-by-n generalization of chess, can black guarantee a win? Frustrating news. Huge number of fundamental problems have defied classification for decades. 4

Polynomial-Time Reduction Purpose. Classify problems according to relative difficulty. Design algorithms. If X P Y and Y can be solved in polynomial-time, then X can also be solved in polynomial time. Establish intractability. If X P Y and X cannot be solved in polynomial-time, then Y cannot be solved in polynomial time. Establish equivalence. If X P Y and Y P notation X P Y. X, we use up to cost of reduction 5

Decision problem. X is a set of strings. Decision Problems Instance: string s. Algorithm A solves problem X: A(s) = yes iff s X. Polynomial time. Algorithm A runs in poly-time if for every string s, A(s) terminates in at most p( s ) "steps", where p( ) is some polynomial. length of s PRIMES: X = { 2, 3, 5, 7, 11, 13, 17, 23, 29, 31, 37,. } Algorithm. [Agrawal-Kayal-Saxena, 2002] p( s ) = s 8. 6

Definition of P P. Decision problems for which there is a poly-time algorithm. Problem Description Algorithm Yes No MULTIPLE Is x a multiple of y? Grade school division 51, 17 51, 16 RELPRIME Are x and y relatively prime? Euclid (300 BCE) 34, 39 34, 51 PRIMES Is x prime? AKS (2002) 53 51 EDIT -DISTANCE Is the edit distance between x and y less than 5? Dynamic programming niether neither acgggt ttttta LSOLVE Is there a vector x that satisfies Ax = b? Gauss-Edmonds elimination # 0 1 1& % ( % 2 4 2 (, $ % 0 3 15' ( # 4& % ( % 2 ( $ % 36' ( " 1 0 0% $ ' $ 1 1 1 ', # $ 0 1 1& ' " 1% $ ' $ 1 ' # $ 1& ' 7

NP Certification algorithm intuition. Certifier views things from "managerial" viewpoint. Certifier doesn't determine whether s X on its own; rather, it checks a proposed proof t that s X. Def. Algorithm C(s, t) is a certifier for problem X if for every string s, s X iff there exists a string t such that C(s, t) = yes. "certificate" or "witness" NP. Decision problems for which there exists a poly-time certifier. C(s, t) is a poly-time algorithm and t p( s ) for some polynomial p( ). Remark. NP stands for nondeterministic polynomial-time. 8

Certifiers and Certificates: 3-Satisfiability SAT. Given a CNF formula Φ, is there a satisfying assignment? Certificate. An assignment of truth values to the n boolean variables. Certifier. Check that each clause in Φ has at least one true literal. Ex. ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) ( x 1 x 3 x 4 ) instance s x 1 =1, x 2 =1, x 3 = 0, x 4 =1 certificate t Conclusion. SAT is in NP. 9

Certifiers and Certificates: Hamiltonian Cycle HAM-CYCLE. Given an undirected graph G = (V, E), does there exist a simple cycle C that visits every node? Certificate. A permutation of the n nodes. Certifier. Check that the permutation contains each node in V exactly once, and that there is an edge between each pair of adjacent nodes in the permutation. Conclusion. HAM-CYCLE is in NP. instance s certificate t 10

NP-Complete NP-complete. A problem Y in NP with the property that for every problem X in NP, X p Y. Theorem. Suppose Y is an NP-complete problem. Then Y is solvable in poly-time iff P = NP. Pf. If P = NP then Y can be solved in poly-time since Y is in NP. Pf. Suppose Y can be solved in poly-time. Let X be any problem in NP. Since X p Y, we can solve X in poly-time. This implies NP P. We already know P NP. Thus P = NP. Fundamental question. Do there exist "natural" NP-complete problems? 11

Circuit Satisfiability Circuit Satisfiability Given a combinational circuit built out of AND, OR, and NOT gates, is there a way to set the circuit inputs so that the output is 1? output yes: 1 0 1 1 0??? hard-coded inputs inputs 12

The "First" NP-Complete Problem Theorem. CIRCUIT-SAT is NP-complete. [Cook 1971, Levin 1973] Pf. (sketch) Any algorithm that takes a fixed number of bits n as input and produces a yes/no answer can be represented by such a circuit. Moreover, if algorithm takes poly-time, then circuit is of poly-size. sketchy part of proof; fixing the number of bits is important, and reflects basic distinction between algorithms and circuits Consider some problem X in NP. It has a poly-time certifier C(s, t). To determine whether s is in X, need to know if there exists a certificate t of length p( s ) such that C(s, t) = yes. View C(s, t) as an algorithm on s + p( s ) bits (input s, certificate t) and convert it into a poly-size circuit K. first s bits are hard-coded with s remaining p( s ) bits represent bits of t Circuit K is satisfiable iff C(s, t) = yes. 13

Independent Set INDEPENDENT SET: Given a graph G = (V, E) and an integer k, is there a subset of vertices S V such that S k, and for each edge at most one of its endpoints is in S? Ex. Is there an independent set of size 6? Yes. Ex. Is there an independent set of size 7? No. independent set 14

Example Ex. Construction below creates a circuit K whose inputs can be set so that K outputs true iff graph G has an independent set of size 2. independent set of size 2? independent set? both endpoints of some edge have been chosen? set of size 2? u v w G = (V, E), n = 3 u-v u-w v-w u v w " n % $ ' # 2 & 1 0 1 hard-coded inputs (graph description)??? n inputs (nodes in independent set) 15

Establishing NP-Completeness Remark. Once we establish first "natural" NP-complete problem, others fall like dominoes. Recipe to establish NP-completeness of problem Y. Step 1. Show that Y is in NP. Step 2. Choose an NP-complete problem X. Step 3. Prove that X p Y. Justification. If X is an NP-complete problem, and Y is a problem in NP with the property that X P Y then Y is NP-complete. Pf. Let W be any problem in NP. Then W P X P Y. By transitivity, W P Y. Hence Y is NP-complete. by definition of NP-complete by assumption 16

17 3-SAT is NP-Complete Theorem. 3-SAT is NP-complete. Pf. Suffices to show that CIRCUIT-SAT P 3-SAT since 3-SAT is in NP. Let K be any circuit. Create a 3-SAT variable x i for each circuit element i. Make circuit compute correct values at each node: x 2 = x 3 add 2 clauses: x 1 = x 4 x 5 add 3 clauses: x 0 = x 1 x 2 add 3 clauses: Hard-coded input values and output value. x 5 = 0 add 1 clause: x 0 = 1 add 1 clause: Final step: turn clauses of length < 3 into clauses of length exactly 3. x 5 x 0 x 2 x 3, x 2 x 3 x 1 x 4, x 1 x 5, x 1 x 4 x 5 x 0 x 1, x 0 x 2, x 0 x 1 x 2 x 5 x 1 output x 4 x 0 0?? x 2 x 3

3-SAT Reduces to Independent Set Claim. 3-SAT P INDEPENDENT-SET. Pf. Given an instance Φ of 3-SAT, we construct an instance (G, k) of INDEPENDENT-SET that has an independent set of size k iff Φ is satisfiable. Construction. G contains 3 vertices for each clause, one for each literal. Connect 3 literals in a clause in a triangle. Connect literal to each of its negations. x 1 x 2 x 1 G x 2 x 3 x x 1 x 2 x 3 4 k = 3 Φ = ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) 18

3-SAT Reduces to Independent Set Claim. G contains independent set of size k = Φ iff Φ is satisfiable. Pf. Let S be independent set of size k. S must contain exactly one vertex in each triangle. Set these literals to true. and any other variables in a consistent way Truth assignment is consistent and all clauses are satisfied. Pf Given satisfying assignment, select one true literal from each triangle. This is an independent set of size k. x 1 x 2 x 1 G k = 3 x 2 x 3 x x 1 x 2 x 3 4 Φ = ( x 1 x 2 x 3 ) ( x 1 x 2 x 3 ) ( x 1 x 2 x 4 ) 19

NP-Completeness Observation. All problems below are NP-complete and polynomial reduce to one another! CIRCUIT-SAT by definition of NP-completeness 3-SAT INDEPENDENT SET DIR-HAM-CYCLE GRAPH 3-COLOR SUBSET-SUM VERTEX COVER HAM-CYCLE PLANAR 3-COLOR SCHEDULING SET COVER TSP 20

Approximation Algorithm Q. Suppose I need to solve an NP-hard problem. What should I do? A. Theory says you're unlikely to find a poly-time algorithm. Must sacrifice one of three desired features. Solve problem to optimality. Solve problem in poly-time. Solve arbitrary instances of the problem. ρ-approximation algorithm. Guaranteed to run in poly-time. Guaranteed to solve arbitrary instance of the problem Guaranteed to find solution within ratio ρ of true optimum. Challenge. Need to prove a solution's value is close to optimum, without even knowing what optimum value is! 21

Load Balancing Input. m identical machines; n jobs, job j has processing time t j. Job j must run contiguously on one machine. A machine can process at most one job at a time. Def. Let J(i) be the subset of jobs assigned to machine i. The load of machine i is L i = Σ j J(i) t j. Def. The makespan is the maximum load on any machine L = max i L i. Load balancing. Assign each job to a machine to minimize makespan. 22

Load Balancing: List Scheduling List-scheduling algorithm. Consider n jobs in some fixed order. Assign job j to machine whose load is smallest so far. List-Scheduling(m, n, t 1,t 2,,t n ) { for i = 1 to m { L i 0 // load on machine i J(i) φ // jobs assigned to machine i } for j = 1 to n { i = argmin k L k // machine i has smallest load J(i) J(i) {j} // assign job j to machine i L i L i + t j // update load of machine i } } Implementation. O(n log n) using a priority queue. 23

Load Balancing: List Scheduling Analysis Theorem. [Graham, 1966] Greedy algorithm is a 2-approximation. First worst-case analysis of an approximation algorithm. Need to compare resulting solution with optimal makespan L*. Lemma 1. The optimal makespan L* max j t j. Pf. Some machine must process the most time-consuming job. Lemma 2. The optimal makespan Pf. L * m 1 j t j. 1. The total processing time is Σ j t j. 2. One of m machines must do at least a 1/m fraction of total work. 24

Load Balancing: List Scheduling Analysis Theorem. Greedy algorithm is a 2-approximation. Pf. Consider load L i of bottleneck machine i. Let j be last job scheduled on machine i. When job j assigned to machine i, i had smallest load. Its load before assignment is L i - t j L i - t j L k for all 1 k m. blue jobs scheduled before j machine i j 0 L i - t j L = L i 25

Load Balancing: List Scheduling Analysis Theorem. Greedy algorithm is a 2-approximation. Pf. Consider load L i of bottleneck machine i. Let j be last job scheduled on machine i. When job j assigned to machine i, i had smallest load. Its load before assignment is L i - t j L i - t j L k for all 1 k m. Sum inequalities over all k and divide by m: Lemma 1 L i t j 1 m k L k = 1 m k t k L * Now L i = (L i t j )!# "# $ + t j % L* L* 2L *. Lemma 2 26

Load Balancing: List Scheduling Analysis Q. Is our analysis tight? A. Essentially yes. Ex: m machines, m(m-1) jobs length 1 jobs, one job of length m m = 10 machine 2 idle machine 3 idle machine 4 idle machine 5 idle machine 6 idle machine 7 idle machine 8 idle machine 9 idle machine 10 idle list scheduling makespan = 19 27

Load Balancing: List Scheduling Analysis Q. Is our analysis tight? A. Essentially yes. Ex: m machines, m(m-1) jobs length 1 jobs, one job of length m m = 10 optimal makespan = 10 28

Load Balancing: LPT Rule Longest processing time (LPT). Sort n jobs in descending order of processing time, and then run list scheduling algorithm. LPT-List-Scheduling(m, n, t 1,t 2,,t n ) { Sort jobs so that t 1 t 2 t n for i = 1 to m { L i 0 J(i) φ } load on machine i jobs assigned to machine i } for j = 1 to n { i = argmin k L k J(i) J(i) {j} L i L i + t j } machine i has smallest load assign job j to machine i update load of machine i 29

Load Balancing: LPT Rule Observation. If at most m jobs, then list-scheduling is optimal. Pf. Each job put on its own machine. Lemma 3. If there are more than m jobs, L* 2 t m+1. Pf. Consider first m+1 jobs t 1,, t m+1. Since the t i 's are in descending order, each takes at least t m+1 time. There are m+1 jobs and m machines, so by pigeonhole principle, at least one machine gets two jobs. Theorem. LPT rule is a 3/2 approximation algorithm. Pf. Same basic approach as for list scheduling. L i = (L i t j )!# "# $ + t j % 2 3 L *. L* 1 2 L* Lemma 3 ( by observation, can assume number of jobs > m ) 30

Metric TSP TSP: A salesman must visit n cities to sell goods and go back with minimum cost. Def. G=<V,E> is complete undirected graph, each edge (u,v) in E has a nonnegative cost c(u,v). TSP is to find a hamiltonian cycle of G with minum cost Triangle inequality c ( u, w) c( u, v) + c( v, w) 31

Metric TSP Algorithm based on Minimum Spanning Tree Approx-TSP-Tour(G, c) { Select a vertex r in V as a root. Compute a MST T of G with root r. Walk on T in preorder and generate a list L. Return the hamiltonian cycle H with vertices in the order L. } 32

Lemma. C(T) C(H*) Metric TSP: Analysis Theorem. Approx-TSP-Tour is a 2 approximation algorithm Pf. The walk W satisfies C(W) = 2C(T) With lemma, we have C(W) 2C(H*) For C(H) C(W), we have C(H) 2C(H*) 33

Improved Metric TSP Observation: There are even vertices with odd degree in a tree NApprox-TSP-Tour(G, c) { Select a vertex r in V as a root. Compute a MST T of G with root r. Compute a minimum perfect matching M on the set of odd-degree veritces of T. Add M to T. Return the hamiltonian cycle H with vertices in the order Euler tour L. } 34

Improved Metric TSP: Analysis Lemma. C(M) C(H*)/2 Pf. Vertices with odd degree can form a cycle MC by bypassing the other vertices in HC. We have C(MC) C(H*) The minimum perfect match M of these vertices satisfies C(M) C(MC)/2. Theorem. NApprox-TSP-Tour is a 3/2 approximation algorithm Pf. The Euler tour L satisfies C(L) C(T) + C(M) C(H*) + C(H*)/2 35

Inapproximability: General TSP Theorem. If P NP, for any constant ρ 1 there is no polynomial-time approximation algorithm with approximation ratio ρ for the general TSP. Pf. Apply this approximation algorithm to find a Hamiltonian cycle. Assign c(u,v) = 1 if (u,v) in E, otherwise c(u,v) = ρ V + 1. 36

Next week Randomized algorithms Chapter 13 (Algorithm Design) 37