Lecture 19 CSE 331 Oct 19, 2009

advertisement
Lecture 19
CSE 331
Oct 19, 2009
Announcements
Solutions to HW4 and HW5 at the END of the lecture
Graded HWs and mid-term by this week
Sign up for blog posts: OCT 30 is now open
Hope last week was fun
Hung’s notes
will be up
today
Main Steps in Algorithm Design
Problem Statement
Problem Definition
Algorithm
n!
“Implementation”
Analysis
Data Structures
Correctness+Runtime Analysis
Where do graphs fit in?
Problem Statement
A tool to define
problems
Problem Definition
Algorithm
“Implementation”
Analysis
Data Structures
Correctness+Runtime Analysis
Rest of the course
Problem Statement
Problem Definition
Three general
techniques
Algorithm
“Implementation”
Analysis
Data Structures
Correctness+Runtime Analysis
Greedy algorithms
Build the final solution piece by piece
Being short sighted on each piece
Never undo a decision
Know when you see it
End of Semester blues
Can only do one thing at any day: what is the
maximum number of tasks that you can do?
Write up a term paper
Party!
Exam study
331 homework
331 HW
Project
Monday
Tuesday
Wednesday
Thursday
Friday
Greedily solve your blues!
Arrange tasks in some order and iteratively pick nonoverlapping tasks
Write up a term paper
Party!
Exam study
331 HW
Project
Monday
Tuesday
Wednesday
Thursday
Friday
Ordering is crucial
Order by starting time
Write up a term paper
Party!
Algo =1
Exam study
331 HW
Project
Monday
Tuesday
Wednesday
Thursday
Friday
Another attempt
Order by duration
Ordering by least
conflicts doesn’t
work
Algo =1
Monday
Tuesday
Wednesday
Thursday
Friday
The final algorithm
Order tasks by their END time
Write up a term paper
Party!
Exam study
331 HW
Project
Monday
Tuesday
Wednesday
Thursday
Friday
Formal Algorithm
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 A
Questions?
Analyzing the algorithm
R: set of requests
Set A to be the empty set
A has no
conflicts
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
A is an
optimal
solution
Greedy “stays ahead”
A = i1,…,ik
O = j1,…,jm
k=m
What do we need to
prove?
What can you say about f(i1) and
f(j1)?
A formal claim
For every r ≤ k, f(ir) ≤ f(jr)
The greedy algorithm outputs an optimal A
Proof by contradiction: A is not optimal
A = i1,…,ik
O = j1,…,jm
m>k
ik
jk
After ik, R was
non-empty!
No conflict!
jk+1
Proof of claim
For every r ≤ k, f(ir) ≤ f(jr)
By induction on r
Why is r=1 OK?
Assume true up to r-1
Greedy can always pick
jr
ir-1
jr-1
ir
jr
?
Rest of today’s agenda
Analyze run-time of the greedy algorithm
Another scheduling problem
Related documents
Download