This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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(n1) + F(n2) Fib( n:integer) { if ( n==0 or n==1 ) return 1 else return Fib(n1) + Fib(n2) } What’s 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(n1,F) + Fib1(n2,F) return F[n] } What’s the running time? 5 Fibonacci Numbers Nonrecursive solution Fib( n: int) { F[0] = 1 F[1] = 1 for i=2 to n do F[i] = F[i1] + F[i2] 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( i1, y) + f (i,xy) } 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 MF’s? 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 MF’s? 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
This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.
 Spring '08
 M.McCullen
 Algorithms, C Programming, Data Structures

Click to edit the document details