lecture14DynProgramming

# lecture14DynProgramming - Dynamic Programming Algorithm...

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

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.

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

View Full Document
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?
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

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

View Full Document
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?
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?

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

View Full Document
6 Memoizing Memoize 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) }

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

View Full Document
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

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

View Full Document
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
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

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.

## 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.

### Page1 / 54

lecture14DynProgramming - Dynamic Programming Algorithm...

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

View Full Document
Ask a homework question - tutors are online