lecture14DynProgramming

lecture14DynProgramming - Dynamic Programming Algorithm...

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

View Full Document Right Arrow Icon
1 Dynamic Programming Algorithm design technique 2 A problem with some (trivial) algorithms: Computing the same thing over and over again. Dynamic programming Systematically records answers to subproblems so they are not recomputed.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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) } What’s the running time?
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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) + Fib1(n-2) return F[n] } What’s the running time?
Background image of page 4
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?
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Memoizing Memoize A technique used to speed up algorithms by storing results rather than recomputing them. Basic idea of dynamic programming.
Background image of page 6
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) }
Background image of page 7

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

View Full DocumentRight Arrow Icon
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?
Background image of page 8
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 MF’s? Best return on $100M
Background image of page 9

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

View Full DocumentRight Arrow Icon
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 MF’s? Best return on $200M
Background image of page 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 16 Best return for $100M to $600M? How about
Background image of page 11

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

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

Page1 / 54

lecture14DynProgramming - Dynamic Programming Algorithm...

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