15-251 Great Theoretical Ideas in Computer Science.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science
Advertisements

Great Theoretical Ideas in Computer Science for Some.
Reducibility Class of problems A can be reduced to the class of problems B Take any instance of problem A Show how you can construct an instance of problem.
1 NP-completeness Lecture 2: Jan P The class of problems that can be solved in polynomial time. e.g. gcd, shortest path, prime, etc. There are many.
1 The TSP : Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell ( )
NP-Complete Problems Polynomial time vs exponential time
Great Theoretical Ideas in Computer Science for Some.
CSE373: Data Structures & Algorithms Lecture 24: The P vs. NP question, NP-Completeness Nicki Dell Spring 2014 CSE 373 Algorithms and Data Structures 1.
Combinatorial Algorithms
Discrete Structures & Algorithms The P vs. NP Question EECE 320.
Great Theoretical Ideas in Computer Science.
CSC5160 Topics in Algorithms Tutorial 2 Introduction to NP-Complete Problems Feb Jerry Le
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
Computational problems, algorithms, runtime, hardness
Approximation Algorithms: Combinatorial Approaches Lecture 13: March 2.
Great Theoretical Ideas in Computer Science.
The Theory of NP-Completeness
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
Analysis of Algorithms CS 477/677
1 NP-Complete Problems Polynomial time vs exponential time –Polynomial O(n k ), where n is the input size (e.g., number of nodes in a graph, the length.
February 25, 2015CS21 Lecture 211 CS21 Decidability and Tractability Lecture 21 February 25, 2015.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
Complexity Theory: The P vs NP question Lecture 28 (Dec 4, 2007)
Programming & Data Structures
Algorithms for Network Optimization Problems This handout: Minimum Spanning Tree Problem Approximation Algorithms Traveling Salesman Problem.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
Great Theoretical Ideas in Computer Science.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
TECH Computer Science NP-Complete Problems Problems  Abstract Problems  Decision Problem, Optimal value, Optimal solution  Encodings  //Data Structure.
Approximation Algorithms
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Approximation Algorithms These lecture slides are adapted from CLRS.
COMPSCI 102 Introduction to Discrete Mathematics.
The Traveling Salesman Problem Over Seventy Years of Research, and a Million in Cash Presented by Vladimir Coxall.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
COMPSCI 102 Introduction to Discrete Mathematics.
CSE373: Data Structures & Algorithms Lecture 22: The P vs. NP question, NP-Completeness Lauren Milne Summer 2015.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Lecture 6 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
CPS Computational problems, algorithms, runtime, hardness (a ridiculously brief introduction to theoretical computer science) Vincent Conitzer.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
NPC.
CSC 413/513: Intro to Algorithms
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
Approximation Algorithms by bounding the OPT Instructor Neelima Gupta
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Great Theoretical Ideas In Computer Science Anupam GuptaCS Fall 2006 Lecture 28Dec 7th, 2006Carnegie Mellon University Complexity Theory: the P.
Great Theoretical Ideas in Computer Science.
Conceptual Foundations © 2008 Pearson Education Australia Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics.
TU/e Algorithms (2IL15) – Lecture 11 1 Approximation Algorithms.
The NP class. NP-completeness
More NP-Complete and NP-hard Problems
Lecture 2-2 NP Class.
Great Theoretical Ideas in Computer Science
Great Theoretical Ideas in Computer Science
Discrete Mathematics for Computer Science
Chapter 34: NP-Completeness
Approximation Algorithms
Presentation transcript:

Great Theoretical Ideas in Computer Science

Approximation and Online Algorithms Lecture 28 (November 30, 2010)

In the previous lecture, we saw two problem classes: P and NP

The Class P We say a set L  Σ * is in P if there is a program A and a polynomial p( ) such that for any x in Σ *, A(x) runs for at most p(|x|) time and answers question “is x in L?” correctly.

The class of all sets L that can be recognized in polynomial time. The class of all decision problems that can be decided in polynomial time. The Class P

P contains many useful problems: graph connectivity minimum spanning tree matchings in graphs shortest paths solving linear systems Ax = b linear programming maximum flows Many of this we will (re)visit in

NP A set L  NP if there exists an algorithm V and a polynomial p( ) such that For all x  L there exists y with |y|  p(|x|) such that V(x,y) = YES in p(|x|) time For all x  L For all y with |y|  p(|x|) in p(|x|) time such that V(x,y) = NO “exists a quickly-verifiable proof” “all non-proofs rejected”

The Class NP The class of sets L for which there exist “short” proofs of membership (of polynomial length) that can be “quickly” verified (in polynomial time). Recall: V doesn’t have to find these proofs y; it just needs to be able to verify that y is a “correct” proof.

P  NP For any L in P, we take the “proof” y to be the empty string, and V(x,y) = A(x) to satisfy the requirements. Hence, every language in P is also in NP. in this case, “the computation is the proof”

Summary: P versus NP Set L is in P if membership in L can be decided in poly-time. Set L is in NP if each x in L has a short “proof of membership” that can be verified in poly-time. Fact: P  NP Million (Billion) $ question: Does NP  P ?

NP-hard and NP-complete L is NP-hard if a polynomial-time algorithm for L implies a polynomial-time algorithm for all of NP L is NP-complete if L is NP-hard and L itself belongs to NP. to show NP-hardness for L, find another NP-hard problem (say SAT), and reduce SAT to L.

Classroom Scheduling Packing objects into bins Scheduling jobs on machines Finding cheap tours visiting a subset of cities Allocating variables to registers Finding good packet routings in networks Decryption … NP Contains Lots of Problems We Don’t Know to be in P

What do we do now? We’d really like to solve these problems. But we don’t know how to solve them in polynomial time… A solution for some of these: Try to solve them “approximately”

E.g. Scheduling Jobs on Machines Input: A set of n jobs, each job j has processing time p j A set of m identical machines

E.g.: m=4 machines, n=8 jobs

E.g. Scheduling Jobs on Machines Input: A set of n jobs, each job j has processing time p j A set of m identical machines Is MinMakespan NP-hard? Allocate these n jobs to these m machines to minimize the load of the worst-loaded machine. (We call this objective function the “makespan”) We call this problem MinMakespan

NP hardness proof To prove NP hardness, find a problem such that b) if you can solve MinMakespan quickly, you can solve that problem quickly a) that problem is itself NP hard Can you suggest such a problem?

The (NP hard) Partition Problem Given a set A = {a 1, a 2,…,a n } of n naturals which sum up to 2B (B is a natural), does there exist a subset of these that sums to exactly B? a) Partition is NP hard so we’ve found a problem Partition such that: Call this problem “Partition”

b) if you can solve MinMakespan quickly, you can solve Partition quickly Take any instance (A = {a 1, …, a n }, B) of Partition Each natural number in A corresponds to a job. The processing time p j = a j We have m = 2 machines. Easy Theorem: there is a solution with makespan = B iff there is a partition of A into two equal parts.  if you solve Makespan fast, you solve Partition fast.  if Partition is hard, Makespan is hard.

MinMakespan Partition NP-hard If MinMakespan in polynomial-time then Partition in polynomial-time hence MinMakespan NP-hard we just took an instance of Partition and reduced it to MinMakespan then MinMakespan is also hard so, if Partition is hard

What do we do now??? Finding the best solution is hard but can we find something that is not much worse than the best? Can you suggest an algorithm?

Graham’s Greedy Algorithm Order the jobs j 1, j 2, …, j n in some order Assign j t to the least loaded machine so far Initially all the machines are empty For t = 1 to n

Graham’s Greedy Algorithm Order the jobs j 1, j 2, …, j n in some order Assign j t to the least loaded machine so far Initially all the machines are empty For t = 1 to n

Theorem: The Makespan GGA of this algorithm is at most 2 × OptimalMakespan How do you argue what the optimal value is? Suppose you could show that 1.Makespan GGA ≤ 2 Blah, and 2.Blah ≤ OPT, then you are done. “OPT”

Claim 1: p max ≤ OPT Proof: At least one machine gets the largest job. Claim 2: (  t ≤ n p t )/m ≤ OPT Proof: At least one machine must have at least the average load. Two candidates for “Blah”

OPT may be much larger than either of these two. E.g., n jobs of size 1 OPT = n/m, p max = 1 E.g., 1 job of size m OPT = m, average load = 1 p max (  t ≤ n p t )/m Main insight: OPT cannot be simultaneously larger than both!

Claim 3: Makespan GGA ≤ p max + (  t ≤ n p t )/m Look at the heaviest loaded machine. Look at the last job j k we scheduled on this machine. The load of that machine (at that time) was at most the average (  (t ≤ k-1) p t )/m ≤ (  t ≤ n p t )/m This last job contributes a load of p k ≤ p max Total load on this machine ≤ p max + (  t ≤ n p t )/m

Claim 1: p max ≤ OPT Claim 2: (  t ≤ n p t )/m ≤ OPT Claim 3: Makespan GGA ≤ p max + (  t ≤ n p t )/m ≤ OPT + OPT Theorem: The Makespan GGA of this algorithm is at most 2 × OPT To recap

Two obvious questions Can we analyse this algorithm better? Can we give a better algorithm?

Is the Algorithm any better? Makespan GGA ≤ p max (1-1/m) + (  t ≤ n p t )/m ≤ OPT (2-1/m) Being slightly more careful a few slides back: But we cannot do better with this algorithm

Bad example (If only we hadn’t spread out the small jobs earlier…) With (m-1)L jobs of size 1 before one job of size L 4

Is the Algorithm any better? With (m-1)L jobs of size 1 before one job of size L OPT = L Makespan GGA = L(m-1)/m + L = L(2 – 1/m)

Graham’s Greedy Algorithm Order the jobs j 1, j 2, …, j n in some order Assign j t to the least loaded machine so far Initially all the machines are empty For t = 1 to n decreasing order of size Better

Theorem: Makespan GBGA ≤ 1.5 OPT Better Suppose max-load machine has only one job j t Then we are optimal. (p t ≤ p max ≤ OPT) Else let j t be last job GBGA scheduled on it. Just before it, all machines have at least one job each. So there are m+1 jobs with length at least p t Hence 2p t ≤ OPT (by the non-increasing ordering of the jobs) (since we allocated j t to the least loaded machine) p t ≤ OPT/2 (by pigeonhole)

Makespan GBGA ≤ p t + (  k ≤ n p k )/m p t ≤ OPT/2 (  k ≤ n p k )/m ≤ OPT  Makespan GBGA ≤ 1.5 OPT

In fact, it can be shown that Makespan GBGA ≤ (4/3 – 1/3m) OPT The proof is not hard, but we’ll not do it here. You can show examples where GBGA is at least (4/3 – 1/3m) OPT And there are algorithms which do better than 4/3 but they are much more complicated…

This is the general template to safely handle problems you encounter that may be NP-hard (as long as you cannot prove P = NP) Let’s skim over the steps with another problem as an example…

E.g. The Traveling Salesman Problem (TSP) Input: A set of n cities, with distance d(i,j) between each pair of cities i and j. Assume that d(i,k) ≤ d(i,j)+d(j,k) (triangle inequality) Find the shortest tour that visits each city exactly once NP hard!

Prove it is NP-hard To prove NP hardness, find a problem such that b) if you can solve TSP quickly, you can solve that problem quickly a) that problem is itself NP hard Can you suggest such a problem? Hamilton Cycle

Hamilton Cycle (HAM) Given a graph G = (V,E), a cycle that visits all the nodes exactly once a) that problem is itself NP hard

b) if you can solve TSP quickly, you can solve HAM quickly Take any instance G of HAM with n nodes. Each node is a city. If (i,j) is an edge in G, set d(i,j) = 1 If (i,j) is not an edge, set d(i,j) = 2 Note: d(.,.) satisfies triangle inequality Easy Theorem: any tour of length n is a Hamilton cycle in G  if you solve TSP, you find a Hamilton cycle.

Since it is NP hard to solve exactly, try to find an approximately good solution From Lecture 18: Find a minimum spanning tree Walk “around” the MST and take shortcuts if a node has already been visited Shortcuts only decrease the cost, so Cost(Greedy Tour)  2 Cost(MST)  2 Cost(Optimal Tour) this is a “2-approximation” to TSP

And try to improve it… [Christofides (CMU) 1976]: There is a simple 1.5-approximation algorithm for TSP. Theorem: If you give a approximation for TSP then P=NP. What is the right answer? Still a major unsolved problem…

Many cool combinatorial problems that arise in analyzing algorithms. The mathematical tools you’ve learnt in this course are extremely relevant for their analysis.

Here’s What You Need to Know… NP hardness How to prove NP-hardness (via reductions from hard problems) Approximation Algorithms If you can’t solve it exactly try to solve it as best you can Scheduling Jobs on Parallel Machines Graham’s Greedy Algorithm Analysis