{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 18 - Dynamic Programming Data Structures and Algorithms...

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

Dynamic Programming Data Structures and Algorithms Andrei Bulatov

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

View Full Document
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 . 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 0 1 2 3 4 5 6 7 8 9 10 11 b a weight = 999 weight = 1

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

View Full Document
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. 1 Time 0 1 2 3 4 5 6 7 8 9 10 11 6 7 8 4 3 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 } 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 0 j 0 ) ( j OPT j p OPT v j OPT j optimal substructure

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

View Full Document
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) 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 0 1 0 1 0

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

View Full Document
Algorithms – Dynamic Programming 18-8 Weighted Interval Scheduling: Memoization Memoization : Store results of each sub-problem in a cache; lookup as needed. 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) 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 Sort by finish time: O(n log n). Theorem Memoized version of algorithm takes O(n log n) time.

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.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online