lecture 20 cse 331 oct 21, 2009. algorithm for interval scheduling r: set of requests set a to be...
Post on 22-Dec-2015
217 views
TRANSCRIPT
Algorithm for Interval Scheduling
R: set of requests
Set A to be the empty set
While R is not empty
Choose i in R with the earliest finish time
Add i to A
Remove all requests that conflict with i from R
Return AA is optimalA is optimal
Run time analysis
Set A to be the empty set
While R is not empty
Choose i in R with the earliest finish time
Add i to A
Remove all requests that conflict with i from R
Return A
O(n log n) time sort intervals such that f(i) ≤ f(i+1)O(n log n) time sort intervals such that f(i) ≤ f(i+1)
O(n) time build array s[1..n] s.t. s[i] = start time for iO(n) time build array s[1..n] s.t. s[i] = start time for i
Today’s agenda
Finish run time analysis
A more realistic scheduling problem for end of semester blues
Run time analysis
Set A to be the empty set
While R is not empty
Choose i in R with the earliest finish time
Add i to A
Remove all requests that conflict with i from R
Return A
O(n log n) time sort intervals such that f(i) ≤ f(i+1)O(n log n) time sort intervals such that f(i) ≤ f(i+1)
O(n) time build array s[1..n] s.t. s[i] = start time for iO(n) time build array s[1..n] s.t. s[i] = start time for i
Do the removal on
the fly
Do the removal on
the fly
Algorithm implementation
Go through the intervals in order of their finish time
11
22
33
44
How can you tell in O(1) time if any of 2,3 or 4 conflict
with 1?
How can you tell in O(1) time if any of 2,3 or 4 conflict
with 1?
Check if s[i] < f(1)Check if s[i] < f(1)
In general, if jth interval is the last one chosen
Pick smallest i>j such that s[i] ≥ f(j)O(n log n) run
timeO(n log n) run
time
The “real” end of Semester blues
Monday Tuesday Wednesday Thursday Friday
ProjectProject
331 HW331 HWExam studyExam study
Party!Party!
Write up a term paperWrite up a term paper
There are deadlines and durations of tasks
There are deadlines and durations of tasks
The “real” end of Semester blues
Monday Tuesday Wednesday Thursday Friday
ProjectProject
331 HW331 HW
Exam studyExam study
Party!Party!
Write up a term paperWrite up a term paper
There are deadlines and durations of tasks
There are deadlines and durations of tasks
The algorithmic task
Monday Tuesday Wednesday Thursday Friday
ProjectProject
331 HW331 HW
Exam studyExam study
Party!Party!
Write up a term paperWrite up a term paper
YOU decide when to start each task
YOU decide when to start each task
You have to do ALL the tasks
You have to do ALL the tasks
Scheduling to minimize lateness
Monday Tuesday Wednesday Thursday Friday
ProjectProject
331 HW331 HW
Exam studyExam study
Party!Party!
Write up a term paperWrite up a term paper
All the tasks have to be scheduledGOAL: minimize maximum latenessAll the tasks have to be scheduled
GOAL: minimize maximum lateness
One possible schedule
Monday Tuesday Wednesday Thursday Friday
331 HW331 HW Exam studyExam studyParty!Party! Write up a term paperWrite up a term paper
All the tasks have to be scheduledGOAL: minimize maximum latenessAll the tasks have to be scheduled
GOAL: minimize maximum lateness
Lateness = 0Lateness = 0 Lateness = 2Lateness = 2