Lecture16a

# Lecture16a - CSE 421 Algorithms Richard Anderson Lecture...

This preview shows pages 1–10. Sign up to view the full content.

CSE 421 Algorithms Richard Anderson Lecture 16a Dynamic Programming

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Dynamic Programming Weighted Interval Scheduling • Given a collection of intervals I 1 ,…,I n with weights w 1 ,…,w n , choose a maximum weight set of non-overlapping intervals Sorted by finish times 4 6 3 5 7 6
Recursive Algorithm Intervals sorted by finish time p[i] is the index of the last interval which finishes before i starts 1 2 3 4 5 6 7 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Optimality Condition Opt[j] is the maximum weight independent set of intervals I 1 , I 2 , . . ., I j Opt[ j ] = max( Opt[ j – 1], w j + Opt[ p [ j ] ])
Algorithm MaxValue(j) = if j = 0 return 0 else return max( MaxValue(j-1), w j + MaxValue(p[ j ]))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Run time What is the worst case run time of MaxValue Design a worst case input
A better algorithm M[ j ] initialized to -1 before the first recursive call for all j MaxValue(j) = if j = 0 return 0; else if M[ j ] != -1 return M[ j ]; else M[ j ] = max(MaxValue(j-1),w j + MaxValue(p[ j ])); return M[ j ];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Iterative Algorithm Express the MaxValue algorithm as an iterative algorithm MaxValue { }
Fill in the array with the Opt values Opt[ j ] = max (Opt[ j – 1], w j + Opt[ p[ j ] ]) 4 7 4 6 7 6 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/25/2012 for the course CSE 421 taught by Professor Richardanderson during the Fall '06 term at University of Washington.

### Page1 / 21

Lecture16a - CSE 421 Algorithms Richard Anderson Lecture...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online