lecture16DynProgramminDesign4

lecture16DynProgramminDesign4 - 1 Dynamic Programming An...

Info iconThis preview shows pages 1–12. 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

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: 1 Dynamic Programming An algorithm design technique Decompose problems in different ways Different divisions lead to different solutions One is optimal Systematically records answers to subproblems so they are not recomputed. 2 Fibonacci numbers F(1) = F(0) = 1 F(n) = F(n-1) + F(n-2) Fib( n:integer) { if ( n==0 or n==1 ) return 1 else return Fib(n-1) + Fib(n-2) } Whats the running time? 3 F(5) F(4) F(3) F(3) F(2) F(2) F(1) F(2) F(1) F(1) F(0) F(1) F(0) F(1) F(0) Running Time is O(2 N ) Running Time of Algorithm 4 Fibonacci numbers Dynamic programming solution Fib( n: int) { for i=0 to n do F[i] = -1 ; Flag as not known return Fib1(n, F) } Fib1( n:integer, F: integer array) { if F[n] < 0 do if ( n==0 or n==1 ) F[n] = 1 else F[n] = Fib1(n-1,F) + Fib1(n-2,F) return F[n] } Whats the running time? 5 Fibonacci Numbers Non-recursive solution Fib( n: int) { F[0] = 1 F[1] = 1 for i=2 to n do F[i] = F[i-1] + F[i-2] return F[n] } Can we do this without the array? 6 Memorizing Memorize A technique used to speed up algorithms by storing results rather than recomputing them. Basic idea of dynamic programming. 7 Investment Problem Instance : Return of Investment F(i,x): return for investment option i with investment x 100 200 300 400 500 600 (in M$) CD: 5 11 16 23 29 35 MF: 4 10 18 27 30 37 Land: 4 5 5 30 30 35 IRA: 6 12 17 24 30 31 Best return for $600M? $600M in Mutual Fund: Return is $37M $400M in Land and $200M in IRA: Return is $30M + $12M = $42M How can we compute the best possible return? Apply the principle of optimality. F(i,x): max return for amount x when options 1..i are available. F(i,x) = max { 0 y x} { F( i-1, y) + f (i,x-y) } 8 Investment Problem Instance : Return of Investment F(i,x): return for investment option i with investment x 100 200 300 400 500 600 (in M$) CD: 5 11 16 23 29 35 MF: 4 10 18 27 30 37 Land: 4 5 5 30 30 35 IRA: 6 12 17 24 30 31 Best: 5 11 16 23 29 35 Best return for $100M to $600M? What if we only had CDs? How to compute? 9 Investment Problem Instance : Return of Investment F(i,x): return for investment option i with investment x 100 200 300 400 500 600 (in M$) CD: 5 11 16 23 29 35 MF: 4 10 18 27 30 37 Land: 4 5 5 30 30 35 IRA: 6 12 17 24 30 31 Best: 5 11 16 23 29 35 Best: 5 Best return for $100M to $600M? How about adding MFs? Best return on $100M 10 Investment Problem Instance : Return of Investment F(i,x): return for investment option i with investment x 100 200 300 400 500 600 (in M$) CD: 5 11 16 23 29 35 MF: 4 10 18 27 30 37 Land: 4 5 5 30 30 35 IRA: 6 12 17 24 30 31 Best: 5 11 16 23 29 35 Best: 5 11 Best return for $100M to $600M? How about adding MFs? Best return on $200M 11 Investment Problem Instance : Return of Investment F(i,x): return for investment option i with investment x 100 200 300 400 500 600 (in M$) CD: 5 11 16 23 29 35 MF: 4 10 18 27 30 37 Land: 4 5 5 30 30 35 IRA: 6 12 17 24 30 31 Best: 5 11 16 23 29 35 Best: 5 11 18 Best return for $100M to $600M?...
View Full Document

Page1 / 46

lecture16DynProgramminDesign4 - 1 Dynamic Programming An...

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

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