This preview shows pages 1–10. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Dynamic Programming Data Structures and Algorithms Andrei Bulatov Algorithms Dynamic Programming 182 Weighted Interval Scheduling Weighted interval scheduling problem . Instance A set of n jobs. Job j starts at s j , finishes at f j , and has weight or value v j . wo jobs mpatible they don't overlap. Two jobs compatible if they don't overlap. Objective Find maximum weight subset of mutually compatible jobs. Algorithms Dynamic Programming 183 Unweighted Interval Scheduling: Review Recall: Greedy algorithm works if all weights are 1. Consider jobs in ascending order of finish time. Add job to subset if it is compatible with previously chosen jobs. Observation . Greedy algorithm can fail spectacularly if arbitrary weights are allowed. Time 1 2 3 4 5 6 7 8 9 10 11 b a weight = 999 weight = 1 Algorithms Dynamic Programming 184 Weighted Interval Scheduling Notation: Label jobs by finishing time: f 1 f 2 . . . f n . Let p(j) be the largest index i < j such that job i is compatible with j. Example . p(8) = 5, p(7) = 3, p(2) = 0. Time 1 2 3 4 5 6 7 8 9 10 11 6 7 8 4 3 1 2 5 Algorithms Dynamic Programming 185 Dynamic Programming: Binary Choice Let OPT(j) denote the value of an optimal solution to the problem consisting of job requests 1, 2, ..., j. Case 1: OPT selects job j. cannot use incompatible jobs { p(j) + 1, p(j) + 2, ..., j  1 } ust include optimal solution to problem consisting of remaining must include optimal solution to problem consisting of remaining compatible jobs 1, 2, ..., p(j) Case 2: OPT does not select job j. must include optimal solution to problem consisting of remaining compatible jobs 1, 2, ..., j1 { }  + = = otherwise if ) 1 ( )), ( ( max j ) ( j OPT j p OPT v j OPT j optimal substructure Algorithms Dynamic Programming 186 Weighted Interval Scheduling: Brute Force Input : n, s 1 ,,s n , f 1 ,,f n , v 1 ,,v n sort jobs by finish times so that f 1 f 2 f n compute p(1), p(2), , p(n) eturn Compute pt(n) return ComputeOpt(n) ComputeOpt(j) if (j = 0) return 0 else return max(v j +ComputeOpt(p(j)),ComputeOpt(j1)) Algorithms Dynamic Programming 187 Weighted Interval Scheduling: Brute Force Observation . Recursive algorithm fails spectacularly because of redundant subproblems exponential algorithms. Example Number of recursive calls for family of "layered" instances grows like Fibonacci sequence. 3 4 5 1 2 p(1) = 0, p(j) = j  2 5 4 3 3 2 2 1 2 1 1 1 1 Algorithms Dynamic Programming 188 Weighted Interval Scheduling: Memoization Memoization : Store results of each subproblem in a cache; lookup as needed. Input: , s , ,f , , n, s 1 ,,s n , f 1 ,,f n , v 1 ,,v n sort jobs by finish times so that f 1 f 2 f n compute p(1), p(2), , p(n) set OPT[0]:=0 for j=1 to n do set OPT[j]:=max(v j +OPT[p(j)],OPT[j1]) endfor return OPT[n] Algorithms Dynamic Programming 189 Weighted Interval Scheduling: Running Time Proof...
View
Full
Document
This note was uploaded on 11/19/2009 for the course CS CMPT 307 taught by Professor A.bulatov during the Fall '09 term at Simon Fraser.
 Fall '09
 A.BULATOV
 Algorithms, C Programming, Data Structures

Click to edit the document details