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

cs3000 algorithms data jonathan ullman
SMART_READER_LITE
LIVE PREVIEW

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 ,


slide-1
SLIDE 1

CS3000: ¡Algorithms ¡& ¡Data Jonathan ¡Ullman

Lecture ¡18: ¡

  • Greedy ¡Algorithms: ¡Proof ¡Techniques

March ¡30, ¡2020

slide-2
SLIDE 2

Obligatory ¡Wall ¡Street ¡Quotation

The ¡movie ¡Wall ¡Street, ¡however, ¡is ¡not.

slide-3
SLIDE 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
slide-4
SLIDE 4

Interval ¡Scheduling

slide-5
SLIDE 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

slide-6
SLIDE 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
slide-7
SLIDE 7

Possibly ¡Greedy ¡Rules

  • Choose ¡the ¡shortest ¡interval ¡first
  • Choose ¡the ¡interval ¡with ¡earliest ¡start ¡first
  • Choose ¡the ¡interval ¡with ¡earliest ¡finish ¡first
slide-8
SLIDE 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 ¡𝑇
slide-9
SLIDE 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

slide-10
SLIDE 10

Greedy ¡Stays ¡Ahead

  • Let ¡𝐻 = 𝑗2, … , 𝑗9 be ¡greedy’s ¡schedule
  • Let ¡𝑃 = {𝑘2, … , 𝑘;} be ¡some ¡optimal ¡schedule
  • Key ¡Claim: for ¡every ¡𝑢 = 1, … , 𝑠, ¡𝑔

#> ≤ 𝑔 ?>

slide-11
SLIDE 11

Greedy ¡Stays ¡Ahead

  • Let ¡𝐻 = 𝑗2, … , 𝑗9 be ¡greedy’s ¡schedule
  • Let ¡𝑃 = {𝑘2, … , 𝑘;} be ¡some ¡optimal ¡schedule
  • Key ¡Claim: for ¡every ¡𝑢 = 1, … , 𝑠, ¡𝑔

#> ≤ 𝑔 ?>

slide-12
SLIDE 12

Greedy ¡Stays ¡Ahead

  • Let ¡𝐻 = 𝑗2, … , 𝑗9 be ¡greedy’s ¡schedule
  • Let ¡𝑃 = {𝑘2, … , 𝑘;} be ¡some ¡optimal ¡schedule
  • Key ¡Claim: for ¡every ¡𝑢 = 1, … , 𝑠, ¡𝑔

#> ≤ 𝑔 ?>

slide-13
SLIDE 13

Greedy ¡Stays ¡Ahead

  • Let ¡𝐻 = 𝑗2, … , 𝑗9 be ¡greedy’s ¡schedule
  • Let ¡𝑃 = {𝑘2, … , 𝑘;} be ¡some ¡optimal ¡schedule
  • Key ¡Claim: for ¡every ¡𝑢 = 1, … , 𝑠, ¡𝑔

#> ≤ 𝑔 ?>

slide-14
SLIDE 14

Minimum ¡Lateness ¡Scheduling

slide-15
SLIDE 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

slide-16
SLIDE 16

Possible ¡Greedy ¡Rules

  • Choose ¡the ¡shortest ¡job ¡first ¡(min 𝑢#)?
  • Choose ¡the ¡most ¡urgent ¡job ¡first ¡(min 𝑒# − 𝑢#)?
slide-17
SLIDE 17

Greedy ¡Algorithm: ¡Earliest ¡Deadline ¡First

  • Sort ¡jobs ¡so ¡that ¡𝑒2 ≤ 𝑒4 ≤ ⋯ ≤ 𝑒6
  • For ¡𝑗 = 1, …, 𝑜:
  • Schedule ¡job ¡𝑗 right ¡after ¡job ¡𝑗 − 1 ¡finishes
slide-18
SLIDE 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 ¡𝑃
slide-19
SLIDE 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

slide-20
SLIDE 20

Exchange ¡Argument

  • 𝐻 = ¡greedy ¡schedule, ¡𝑃 = ¡optimal ¡schedule
  • We ¡say ¡that ¡two ¡jobs ¡𝑗, 𝑘 are ¡inverted in ¡𝑃 if ¡ ¡ ¡ ¡ ¡

𝑒# < 𝑒? but ¡𝑘 comes ¡before ¡𝑗

  • Observation: ¡greedy ¡has ¡no ¡inversions
slide-21
SLIDE 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

slide-22
SLIDE 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

slide-23
SLIDE 23

Exchange ¡Argument

  • If ¡𝑗, 𝑘 are ¡a ¡consecutive ¡jobs ¡that ¡are ¡inverted ¡then ¡

flipping ¡them ¡only ¡reduces ¡the ¡lateness

slide-24
SLIDE 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, ¡𝐻 = 𝑃