0% found this document useful (0 votes)
28 views11 pages

Scheduling

The document discusses greedy algorithms for solving interval scheduling problems. It describes several greedy approaches for interval scheduling, including earliest start time, earliest finish time, and shortest interval. It proves that the earliest finish time greedy algorithm produces an optimal schedule by showing that the greedy algorithm's jobs will always finish no later than the optimal jobs at each step. Therefore, the greedy algorithm finds the maximum number of compatible jobs.

Uploaded by

Leena Rohilla
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Scheduling

The document discusses greedy algorithms for solving interval scheduling problems. It describes several greedy approaches for interval scheduling, including earliest start time, earliest finish time, and shortest interval. It proves that the earliest finish time greedy algorithm produces an optimal schedule by showing that the greedy algorithm's jobs will always finish no later than the optimal jobs at each step. Therefore, the greedy algorithm finds the maximum number of compatible jobs.

Uploaded by

Leena Rohilla
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Greedy Algorithms

Interval Scheduling: Section 4.1

Greedy Algorithms
p Optimization problems involve profit
maximization (or cost minimization) under
resource constraints
p Greedy Algorithms build solutions step-by-
step: each step uses “locally optimal”
(short-sighted?) rules to optimize the
objective function

PDF created with pdfFactory trial version www.pdffactory.com


Greed
p “Greed … is good.
Greed is right. Greed
works.”
-- Gordon Gekko
(Michael Douglas) in
the movie Wall Street

Knapsack Problem

Bag of fixed size Chocolates of different sizes

How to maximize the amount of chocolate packed?

PDF created with pdfFactory trial version www.pdffactory.com


Knapsack Problem: greedy

Knapsack Problem: optimal

PDF created with pdfFactory trial version www.pdffactory.com


Interval scheduling
p Set of jobs {1, 2, …, n}
p Job i starts at time si and ends at time fi
p Two jobs compatible if they do not overlap
p Goal: find the maximum subset of
mutually compatible jobs

Interval scheduling

PDF created with pdfFactory trial version www.pdffactory.com


Interval scheduling: greed algorithms
p Greedy approach
n Consider jobs in a specific order
n Choose the “current best” job
n Delete all other jobs that are not compatible
with this job

Interval scheduling: greedy algorithms


p [Earliest start time] Consider jobs in the
ascending order of their start times si
p [Earliest finish time] Consider jobs in
the ascending order of their finish times fi
p [Shortest interval] Consider jobs in the
ascending order of their lengths fi – si
p [Fewest conflicts] For each job i, count
the number of conflicting jobs ci. Consider
jobs in the ascending order of ci

PDF created with pdfFactory trial version www.pdffactory.com


Interval scheduling: greedy algorithms

Earliest finish time

PDF created with pdfFactory trial version www.pdffactory.com


Earliest finish time

Analysis
p Running time = O(n log n)
p Let A be the solution of the greedy
algorithm
n A is a compatible set of requests

PDF created with pdfFactory trial version www.pdffactory.com


Analysis
p Running time = O(n log n)
p Let A be the solution of the greedy
algorithm (earliest finish time algo.)
n A is a compatible set of requests
n A is optimal

Greedy stays ahead


p Let A = i1, i2 , …, ik
p Let OPT be the optimal solution
n OPT = j1,j2,…,jm
p Both A and OPT are arranged in the
natural interval order
p Need to show that k ≥ m

PDF created with pdfFactory trial version www.pdffactory.com


Greedy stays ahead
p [4.2] For all indices r ≤ k we have f(ir) ≤
f(jr)

Greedy stays ahead


p [4.2] For all indices r ≤ k we have f(ir) ≤ f(jr)
p Proof by induction
n Base case: r = 1. Greedy picks the earliest finish time
n Assume f(ir-1) ≤ f(jr-1)
n Can the greedy algorithm’s rth job really finish later than
OPT’s?

PDF created with pdfFactory trial version www.pdffactory.com


Greedy stays ahead
p [4.2] For all indices r ≤ k we have f(ir) ≤ f(jr)
p Proof by induction
n Base case: r = 1. Greedy picks the earliest finish time
n Assume f(ir-1) ≤ f(jr-1)

Greedy stays ahead


p [4.2] For all indices r ≤ k we have f(ir) ≤
f(jr)
p Proof by induction
n Base case: r = 1. Greedy picks the earliest
finish time
n Hypothesis: Let r > 1; assume f(ir-1) ≤ f(jr-1)
n Induction step
p f(ir-1) ≤ f(jr-1) ≤ s(jr)
p Job jr is available after jr-1 finishes for greedy algo;
greedy goes for one with least finish time
p Hence f(ir) ≤ f(jr)

10

PDF created with pdfFactory trial version www.pdffactory.com


Greedy is optimal
p [4.3] The greedy algorithm returns an
optimal set A
n Proof by contradiction: Assume A is not
optimal; lets see what happens
n Let |A| = k and |OPT| = m > k
n f(ik) ≤ f(jk) ≤ s(jk+1)
n After finishing job jk, job jk+1 is available for
greedy – contradicts termination condition for
greedy

Scheduling all intervals: Interval


partitioning problem
p Set of lectures {1, 2, …, n}
p Lecture i starts at time si and ends at fi
p We need to schedule all lectures
n What is the minimum n

11

PDF created with pdfFactory trial version www.pdffactory.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy