{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes07

# notes07 - CSE 2320 Notes 7 Dynamic Programming(Last updated...

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

CSE 2320 Notes 7: Dynamic Programming (Last updated 3/26/12 13:59 A3/P3) D YNAMIC P ROGRAMMING A PPROACH 1. Describe problem input. 2. Determine cost function and base case. 3. Determine general case for cost function. THE HARD PART!!! 4. Appropriate ordering for enumerating subproblems. a. Simple bottom-up approach - from small problems towards the entire big problem. b. Top-down approach with “memoization” - to attack large problems. 5. Backtrace for solution. Most of the effort in dynamic programming is ignored at the end. a. Predecessor/back pointers to get to the subproblems whose results are in the solution. b. Top-down recomputation of cost function (to reach the same subproblems as 5.a) (Providing all solutions is an extra cost feature . . .) 7.A. A S MALL E XAMPLE – Shuttle-to-Airport

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

View Full Document
N W E S Hotel Airport 2 7 9 3 4 8 4 3 2 7 5 4 6 5 8 4 2 2 3 1 1 2 3 2 4 1 How many different paths (by brute force)? Observation: To find optimal route, need optimal route to each street corner. (Could also use Dijkstra’s algorithm, Notes 16, which is more general, but slower.) 1. Describe problem input. Four arrays of paths, each with n values Upper Direct = UD = ud 1 ud 2 . . . ud n = 9 (2 + 7), 9, 3, 4, 8, 7 (4 + 3) Lower Direct = LD = ld 1 ld 2 . . . ld n = 12 (4 + 8), 5, 6, 4, 5, 9 (7 + 2) Upper-to-Lower = UL = ul 1 ul 2 . . . ul n = 2, 3, 1, 3, 4, 0 Lower-to-Upper = LU = lu 1 lu 2 . . . lu n = 2, 1, 2, 2, 1, 0 2. Determine cost function and base case. U(i) = Cost to reach upper corner i L(i) = Cost to reach lower corner i U(0) = 0 L(0) = 0 3. Determine general case. U(i) = min { U(i - 1) + ud i , L(i - 1) + ld i + lu i } L(i) = min { L(i - 1) + ld i , U(i - 1) + ud i + ul i } 2
4. Appropriate ordering of subproblems. U(i) and L(i) cannot be computed without U(i - 1) and L(i - 1) 5. Backtrace for solution – either a. ( shuttle1.c ) explicitly save indication of which of the two cases was used (continue - c, switch - s), or b. ( shuttle2.c ) recheck during backtrace for which case was used. 0 1 2 3 4 5 6 U 0 9 (c) 17 (s) 20 (c) 24 (c) 31 (s) 38 (c) L 0 11 (s) 16 (c) 21 (s) 25 (c) 30 (c) 39 (s) 3

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

View Full Document
Dynamic programming is: 1. Exhaustive search without brute force. 2. Optimal solution to big problem from optimal solutions to subproblems. 7.B. W EIGHTED I NTERVAL S CHEDULING Input: A set of n intervals numbered 1 through n with each interval i having start time s i , finish time f i , and positive weight v i , Output: A set of non-overlapping intervals to maximize the sum of their weights. (Two intervals i and j overlap if either s i < s j < f i or s i < f j < f i .) Brute-force solution: Enumerate the powerset of the input intervals, discard those cases with overlapping intervals, and compute the sum of the weights for each. 1. Describe problem input. Assume the n intervals are in ascending finish time order, i.e. f i £ f i +1 . Let p i be the rightmost preceding interval for interval i , i.e. the largest value j < i such that intervals i and j do not overlap. If no such interval j exists, p i = 0 . (These values may be computed in Θ n log n ( ) time using binSearchLast() from Notes 1. See wis.bs.c. ) 1 6 11 16 21 26 1 2 3 4 5 6 7 8 9 10 v i p i 5 0 4 0 3 2 2 1 1 4 5 0 4 5 3 7 2 6 1 8 m ( i ) 4
2. Determine cost function and base case.

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 / 23

notes07 - CSE 2320 Notes 7 Dynamic Programming(Last updated...

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

View Full Document
Ask a homework question - tutors are online