18 - Dynamic Programming Data Structures and Algorithms...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Dynamic Programming Data Structures and Algorithms Andrei Bulatov Algorithms Dynamic Programming 18-2 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 18-3 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 18-4 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 18-5 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, ..., j-1 { } - + = = otherwise if ) 1 ( )), ( ( max j ) ( j OPT j p OPT v j OPT j optimal substructure Algorithms Dynamic Programming 18-6 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 Compute-Opt(n) Compute-Opt(j) if (j = 0) return 0 else return max(v j +Compute-Opt(p(j)),Compute-Opt(j-1)) Algorithms Dynamic Programming 18-7 Weighted Interval Scheduling: Brute Force Observation . Recursive algorithm fails spectacularly because of redundant sub-problems 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 18-8 Weighted Interval Scheduling: Memoization Memoization : Store results of each sub-problem 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[j-1]) endfor return OPT[n] Algorithms Dynamic Programming 18-9 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.

Page1 / 36

18 - Dynamic Programming Data Structures and Algorithms...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online