Slide 1Approximation and Online AlgorithmsSlide 3The Class PSlide 5PSlide 7The Class NPSlide 9Summary: P versus NPSlide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53Slide 54Slide 55Slide 56Slide 57Slide 58Slide 59Slide 60Slide 61Slide 62Slide 66Slide 67Slide 6815-251Great Theoretical Ideas in Computer ScienceApproximation and Online AlgorithmsLecture 28 (April 28, 2009)In the previous lecture, we saw two problem classes: P and NPThe Class PWe 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|) timeand 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 PPcontains many useful problems:•graph connectivity•minimum spanning tree•matchings in graphs•shortest paths•solving linear systems Ax = b•linear programming•maximum flowsMany of this we will (re)visit in 15-451.NPA set L NPif there exists an algorithm A and a polynomial p( ) such thatFor all x Lthere exists y with |y| p(|x|) such that A(x,y) = YESin p(|x|) timeFor all x LFor all y with |y| p(|x|) in p(|x|) timesuch that A(x,y) = NO“exists a quickly-verifiable proof”“all non-proofs rejected”The Class NPThe class of sets L for which there exist “short” proofs of membership (of polynomial length) that can be “quickly” verified (in polynomial time).Recall: A doesn’t have to find these proofs y; it just needs to be able to verify that y is a “correct” proof.P NPFor any L in P, we can just take y to be the empty string and satisfy the requirements.Hence, every language in P is also in NP.Summary: P versus NPSet 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 NPMillion (Billion) $ question: Does NP P ?Classroom SchedulingPacking objects into binsScheduling jobs on machinesFinding cheap tours visiting a subset of citiesAllocating variables to registersFinding good packet routings in networksDecryption…NP Contains Lots of ProblemsWe Don’t Know to be in PWhat do we do now?We’d really like to solve these problems.But we don’t know how to solve themin polynomial time…A solution for some of these:Try to solve them “approximately”E.g. Scheduling Jobs on MachinesInput: A set of n jobs, each job j has processing time pjA set of m identical machines52 213213E.g.: m=4 machines, n=8 jobsE.g. Scheduling Jobs on MachinesInput: A set of n jobs, each job j has processing time pjA set of m identical machineswe think it is NP hard…Allocate these n jobs to these m machines to minimize the latest ending time over all jobs.(We call this objective function the “makespan”)NP hardness proofTo prove NP hardness, find a problem such thatb) if you can solve Makespan minimization quickly, you can solve that problem quicklya) that problem is itself NP hardCan you suggest such a problem?The (NP hard) Partition ProblemGiven a set A = {a1, a2,…,an} of n naturals which sum up to 2B (B is a natural), find a subset of these that sums to exactly B.a) the problem is itself NP hardso we’ve found a problem such that:b) if you can solve Partition quickly, you can solve Makespan minimization quicklyTake any instance (A = {a1, …, an}, B) of PartitionEach natural number in A corresponds to a job.The processing time pj = ajWe have m = 2 machines.Easy Theorem: there is a solution with makespan = Biff 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.E.g. Scheduling Jobs on MachinesInput: A set of n jobs, each job j has processing time pjA set of m identical machinesAllocate these n jobs to these m machines to minimizethe ending time of the last job to finish.(We call this objective function the “makespan”)NP hard!What do we do now???Finding the best solution is hardbut can we find something that is not much worse than the best?Can you suggest an algorithm?Graham’s Greedy AlgorithmOrder the jobs j1, j2, …, jn in some orderAssign jt to the least loaded machine so farInitially all the machines are emptyFor t = 1 to nGraham’s Greedy AlgorithmOrder the jobs j1, j2, …, jn in some orderAssign jt to the least loaded machine so farInitially all the machines are emptyFor t = 1 to nTheorem: The MakespanGGA of this algorithmis at most 2 × OptimalMakespanHow do you argue what the optimal value is?You don’t. Suppose you could show that 1.MakespanGGA ≤ 2 Blah, and 2.Blah ≤ OPT, then you are done.“OPT”Claim 1: pmax ≤ OPTProof: At least one machine getsthe largest job.Claim 2: (t ≤ n pt)/m ≤ OPTProof: At least one machine must haveat least the average load.Two candidates for “Blah”OPT may be much largerthan either of these two.E.g., n jobs of size 1OPT = n/m, pmax = 1E.g., 1 job of size mOPT = m, average load = 1pmax(t ≤ n pt)/m Main insight: OPT cannot be simultaneously larger than both!Claim 3: MakespanGGA ≤ pmax + (t ≤ n pt)/m Look at the heaviest loaded machine.Look at the last job jk we scheduled on this machine.The load of that machine (at that time) wasat most the average ((t ≤ k-1) pt)/m ≤ (t ≤ n pt)/mThis last job contributes a load of pk ≤ pmaxTotal load on this machine ≤ pmax + (t ≤ n pt)/mClaim 1: pmax ≤ OPTClaim 2: (t ≤ n pt)/m ≤ OPTClaim 3: MakespanGGA ≤ pmax + (t ≤ n pt)/m ≤ OPT + OPTTheorem: The MakespanGGA of this algorithmis at most 2 × OPTTo recapTwo obvious questionsCan we analyse this algorithm better?Can we give a better algorithm?Is the Algorithm any better?MakespanGGA ≤ pmax(1-1/m) + (t ≤ n pt)/m ≤ OPT (2-1/m)Being slightly more careful a few slides back:With x(m-1) jobs of size 1 before one job of size xBut we cannot do better with this algorithmOPT = xMakespanGGA = x(m-1)/m + x = x(2 – 1/m)Bad example(If only we hadn’t spread out the small jobs earlier…)With x(m-1) jobs of size 1 before one job of size x4Graham’s Greedy AlgorithmOrder the
View Full Document