Lecture16 - CSE 421 Algorithms Richard Anderson Lecture 16...

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

CSE 421 Algorithms Richard Anderson Lecture 16 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
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 ] ]) Where p[ j ] is the index of the last interval which finishes before I j starts

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

View Full Document
Algorithm MaxValue(j) = if j = 0 return 0 else return max( MaxValue(j-1), w j + MaxValue(p[ j ])) Worst case run time: 2 n
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 / 22

Lecture16 - CSE 421 Algorithms Richard Anderson Lecture 16...

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

View Full Document
Ask a homework question - tutors are online