cs3000 algorithms data jonathan ullman
play

CS3000: Algorithms & Data Jonathan Ullman Lecture 18: - 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

  7. Possibly ¡Greedy ¡Rules • Choose ¡the ¡shortest ¡interval ¡first • Choose ¡the ¡interval ¡with ¡earliest ¡start ¡first • Choose ¡the ¡interval ¡with ¡earliest ¡finish ¡first

  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 ¡ 𝑇

  9. Greedy ¡Stays ¡Ahead • 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

  10. Greedy ¡Stays ¡Ahead • Let ¡ 𝐻 = 𝑗 2 , … , 𝑗 9 be ¡greedy’s ¡schedule • Let ¡ 𝑃 = {𝑘 2 , … , 𝑘 ; } be ¡some ¡optimal ¡schedule • Key ¡Claim: for ¡every ¡ 𝑢 = 1, … , 𝑠 , ¡ 𝑔 # > ≤ 𝑔 ? >

  11. Greedy ¡Stays ¡Ahead • Let ¡ 𝐻 = 𝑗 2 , … , 𝑗 9 be ¡greedy’s ¡schedule • Let ¡ 𝑃 = {𝑘 2 , … , 𝑘 ; } be ¡some ¡optimal ¡schedule • Key ¡Claim: for ¡every ¡ 𝑢 = 1, … , 𝑠 , ¡ 𝑔 # > ≤ 𝑔 ? >

  12. Greedy ¡Stays ¡Ahead • Let ¡ 𝐻 = 𝑗 2 , … , 𝑗 9 be ¡greedy’s ¡schedule • Let ¡ 𝑃 = {𝑘 2 , … , 𝑘 ; } be ¡some ¡optimal ¡schedule • Key ¡Claim: for ¡every ¡ 𝑢 = 1, … , 𝑠 , ¡ 𝑔 # > ≤ 𝑔 ? >

  13. Greedy ¡Stays ¡Ahead • Let ¡ 𝐻 = 𝑗 2 , … , 𝑗 9 be ¡greedy’s ¡schedule • Let ¡ 𝑃 = {𝑘 2 , … , 𝑘 ; } be ¡some ¡optimal ¡schedule • Key ¡Claim: for ¡every ¡ 𝑢 = 1, … , 𝑠 , ¡ 𝑔 # > ≤ 𝑔 ? >

  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 • Can ¡only ¡do ¡one ¡job ¡at ¡a ¡time, ¡no ¡overlap • The ¡lateness ¡of ¡job ¡ 𝑗 is ¡ max 𝑔 # − 𝑒 # , 0 • The ¡lateness ¡of ¡a ¡schedule is ¡ max max 𝑔 # − 𝑒 # ,0 #

  16. Possible ¡Greedy ¡Rules • Choose ¡the ¡shortest ¡job ¡first ¡( min 𝑢 # )? • Choose ¡the ¡most ¡urgent ¡job ¡first ¡( min 𝑒 # − 𝑢 # )?

  17. Greedy ¡Algorithm: ¡Earliest ¡Deadline ¡First • Sort ¡jobs ¡so ¡that ¡ 𝑒 2 ≤ 𝑒 4 ≤ ⋯ ≤ 𝑒 6 • For ¡ 𝑗 = 1, …, 𝑜 : • Schedule ¡job ¡ 𝑗 right ¡after ¡job ¡ 𝑗 − 1 ¡ finishes

  18. Exchange ¡Argument • 𝐻 = ¡greedy ¡schedule, ¡ 𝑃 = ¡optimal ¡schedule • Exchange ¡Argument: • We ¡can ¡transform ¡ 𝑃 to ¡ 𝐻 by ¡exchanging ¡pairs ¡of ¡jobs • Each ¡exchange ¡only ¡reduces ¡the ¡lateness ¡of ¡ 𝑃 • Therefore ¡the ¡lateness ¡of ¡ 𝐻 is ¡at ¡most ¡that ¡of ¡ 𝑃

  19. Exchange ¡Argument • 𝐻 = ¡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 • 𝐻 = ¡greedy ¡schedule, ¡ 𝑃 = ¡optimal ¡schedule • We ¡say ¡that ¡two ¡jobs ¡ 𝑗, 𝑘 are ¡inverted in ¡ 𝑃 if ¡ ¡ ¡ ¡ ¡ 𝑒 # < 𝑒 ? but ¡ 𝑘 comes ¡before ¡ 𝑗 • Observation: ¡greedy ¡has ¡no ¡inversions

  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

  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

  23. Exchange ¡Argument • If ¡ 𝑗, 𝑘 are ¡a ¡consecutive ¡jobs ¡that ¡are ¡inverted ¡then ¡ flipping ¡them ¡only ¡reduces ¡the ¡lateness

  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 • 𝐻 is ¡the ¡unique ¡schedule ¡with ¡no ¡inversions, ¡ 𝑃 is ¡ the ¡unique ¡schedule ¡with ¡no ¡inversions, ¡ 𝐻 = 𝑃

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend