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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/25/2012 for the course CSE 2320 taught by Professor Bobweems during the Spring '12 term at UT Arlington.

Page1 / 23

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

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

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