cs3000 algorithms data jonathan ullman
play

CS3000:&Algorithms&&&Data Jonathan&Ullman - PowerPoint PPT Presentation

CS3000:&Algorithms&&&Data Jonathan&Ullman Lecture&18:& Greedy&Algorithms:&Proof&Techniques March&30,&2020 Obligatory& Wall$Street$ Quotation The&movie& Wall$Street


  1. CS3000:&Algorithms&&&Data Jonathan&Ullman Lecture&18:& Greedy&Algorithms:&Proof&Techniques • March&30,&2020

  2. Obligatory& Wall$Street$ Quotation The&movie& Wall$Street ,&however,&is&not.

  3. Greedy&Algorithms • What’s&a&greedy&algorithm? • I&know&it&when&I&see&it • Roughly,&an&algorithm&that&builds&a&solution&myopically& and&never&looks&back&(compare&to&DP) • Typically,&make&a&single&pass&over&the&input&(e.g.&Kruskal) • Why&care&about&greedy&algorithms? • Greedy&algorithms&are&the&fastest&and&simplest& algorithms&imaginable,&and&sometimes&they&work! • Sometimes&make&useful&heuristics&when&they&don’t • Simplicity&makes&them&easy&to&adapt&to&different&models

  4. Interval&Scheduling

  5. (Weighted)&Interval&Scheduling • Input:& ! intervals& " # , % # with&values& & # • Output: a&compatible&schedule& ' with&the&largest& possible&total&value • A&schedule&is&a&subset&of&intervals& ' ⊆ {1, … ,!} • A&schedule& ' is compatible&if&no&two& -, . ∈ ' overlap • The&total&value&of& ' is& ∑ & # #∈1

  6. (Unweighted)&Interval&Scheduling • Input:& ! intervals& " # , % # • Output: a&compatible&schedule& ' with&the&largest& possible&size • A&schedule&is&a&subset&of&intervals& ' ⊆ {1, … ,!} • A&schedule& ' is compatible&if&no&two& -, . ∈ ' overlap O O 0 A compatible subset of 3 size

  7. Possibly&Greedy&Rules • Choose&the&shortest&interval&first 2 3 2 OP 1 GREEDY _I • Choose&the&interval&with&earliest&start&first OP 1 4 C 37 2 s y L GREED • Choose&the&interval&with&earliest&finish&first 30 s c 27

  8. Greedy&Algorithm:&Earliest&Finish&First • Sort&intervals&so&that& % 2 ≤ % 4 ≤ ⋯ ≤ % 6 • Let& ' be&empty • For& - = 1, …, ! : • If&interval& - doesn’t&create&a&conflict,&add& - to& ' • Return& ' 0

  9. Greedy&Stays&Ahead Proof by Induction • How&do&we&know&we&found&an&optimal&schedule • “Greedy&Stays&Ahead” strategy • We’ll&show&that&at&every&point&in&time,&the&greedy& schedule&does&better&than&any&other&schedule f s o io a o i Purple greedy Red some other schedule

  10. Greedy&Stays&Ahead 1,3 5,8 G • Let& 8 = - 2 , … , - 9 be&greedy’s&schedule e x O it • Let& : = {. 2 , … , . ; } be&some&optimal&schedule 0 9214,7 9 3 i • Key$Claim: for&every& < = 1, … , = ,& % # > ≤ % 2 j ? > 5 is 4 8 g 2 ice jig _7 jy 9 O O 00ns rosco O 00 fiah fjafizh fi Efj fj.fi Efg

  11. Greedy&Stays&Ahead • Let& 8 = - 2 , … , - 9 be&greedy’s&schedule O • Let& : = {. 2 , … , . ; } be&some&optimal&schedule 0 • Key$Claim: for&every& < = 1, … , = ,& % # > ≤ % ? > r s suppose Greedy is optimal Claim greedy would also choose fir fjr Ther Sjr O O 00ns As s r fi Ifj fi Efj fish fj fig Efg would also be chosen by greedy

  12. Greedy&Stays&Ahead • Let& 8 = - 2 , … , - 9 be&greedy’s&schedule • Let& : = {. 2 , … , . ; } be&some&optimal&schedule • Key$Claim: for&every& < = 1, … , = ,& % # > ≤ % ? > Proofbylnduction f'IIIII.tn I dHn ti D e f fi case Base Inductive Step then fit fj.ie feet fj If ie IT IT itt e IS IT Jet je

  13. Greedy&Stays&Ahead y subtle pairs g arguing why this i picture is impossible • Let& 8 = - 2 , … , - 9 be&greedy’s&schedule • Let& : = {. 2 , … , . ; } be&some&optimal&schedule • Key$Claim: for&every& < = 1, … , = ,& % # > ≤ % ? > Proofoflnductpoo E fj fit E fit fit t ther If D sun in in l I l TT 17 1 I before Greedy would have considered jet it and chosen it

  14. Minimum&Lateness&Scheduling

  15. Minimum&Lateness&Scheduling • Input:& ! jobs&with&length < # and&deadline @ # • Simplifying&assumption:&all&deadlines&are&distinct • Output: a&minimum_lateness&schedule&for&the&jobs S3 f Csi f sa fa • Can&only&do&one&job&at&a&time,&no&overlap • The&lateness&of&job& - is& max % # − @ # , 0 I no breaks • The&lateness&of&a&schedule is& max max % # − @ # ,0 # schedule This sched has red The 0 lateness you in job 3 j

  16. Possible&Greedy&Rules • Choose&the&shortest&job&first&( min < # )? 1 f d 20 L Jobs 1 4 12 10 Job 2 dz to Hd IMB 2 1 Ida • Choose&the&most&urgent&job&first&( min @ # − < # )? di 2 ti't JobI j da lo Job 2 ta lo 101 11 O I 11111442444444346427 lateness 9 d's dz

  17. Greedy&Algorithm:&Earliest&Deadline&First • Sort&jobs&so&that& @ 2 ≤ @ 4 ≤ ⋯ ≤ @ 6 • For& - = 1, …, ! : • Schedule&job& - right&after&job& - − 1H finishes d 20 Jobs 1 4 1 i e D 12 10 Job 2 dz 10 Greedy would do 0 lateness 2 L then w di 2 C 4 1 Job 1 j da _10 Job 2 lo tz 2 2 ul lateness then would 2 Greely choose

  18. Exchange&Argument • 8 =&greedy&schedule,& : =&optimal&schedule • Exchange&Argument: • We&can&transform& : to& 8 by&exchanging&pairs&of&jobs • Each&exchange&only&reduces&the&lateness&of& : • Therefore&the&lateness&of& 8 is&at&most&that&of& : O G L S S

  19. Exchange&Argument • 8 =&greedy&schedule,& : =&optimal&schedule • Observation:&the&optimal&schedule&has&no&gaps • A&schedule&is&just&an&ordering&of&the&jobs,&with&jobs& scheduled&back_to_back

  20. Exchange&Argument • 8 =&greedy&schedule,& : =&optimal&schedule • We&say&that&two&jobs& -, . are&inverted in& : if&&&&& @ # < @ ? but& . comes&before& - • Observation:&greedy&has&no&inversions di Inversion Inveaonwl consecutive jobs g 0 minus Idi f

  21. Exchange&Argument • We&say&that&two&jobs& -, . are&inverted in& : if&&&&& @ # < @ ? but& . comes&before& - • Claim:&the&optimal&schedule&has&no&inversions • Step&1:&suppose& : has&an&inversion,&then&it&has&an& inversion& -, . where& -, . are&consecutive If a schedule has Alternative Form inversions as good that is at least schedule then there is a without inversions

  22. Exchange&Argument • We&say&that&two&jobs& -, . are&inverted in& : if&&&&& @ # < @ ? but& . comes&before& - • Claim:&the&optimal&schedule&has&no&inversions • Step&1:&suppose& : has&an&inversion,&then&it&has&an& inversion& -, . where& -, . are&consecutive • Step&2:&if& -, . are&a&consecutive&jobs&that&are&inverted& then&flipping&them&only&reduces&the&lateness lateness of E d j t Kitt y di titty II aging I lateness ofj µ Exchange dj Litt l I I di titer it ti i di t.tt

  23. Exchange&Argument • If& -, . are&a&consecutive&jobs&that&are&inverted&then& flipping&them&only&reduces&the&lateness lateness of es de 1dg t Kitt di titty i l i lateness ofj l µ Exchange 1 i i dj Litt 1 I di I titer titt ti i ti di e

  24. Exchange&Argument • We&say&that&two&jobs& -, . are&inverted in& : if&&&&& @ # < @ ? but& . comes&before& - • Claim:&the&optimal&schedule&has&no&inversions • Step&1:&suppose& : has&an&inversion,&then&it&has&an& inversion& -, . where& -, . are&consecutive • Step&2:&if& -, . are&a&consecutive&jobs&that&are&inverted& then&flipping&them&only&reduces&the&lateness • 8 is&the&unique&schedule&with&no&inversions,& : is& the&unique&schedule&with&no&inversions,& 8 = :

Recommend


More recommend