Professional Documents
Culture Documents
Etymology.
Dynamic programming = planning over time.
Secretary of Defense was hostile to mathematical research.
Bellman sought an impressive name to avoid confrontation.
Fib(5)
Fib(4) Fib(3)
Fib(1) Fib(0)
Fib(n):
if n = 0 or 1 then return F[n]
if F[n 1] = NIL then F[n 1] := Fib(n 1)
if F[n 2] = NIL then F[n 2] := Fib(n 2)
return ( F[n 1] + F[n 2] )
F returns 3+2 = 5,
0 0 Fib(5)
fills in F[5] with 5
1 1
2 1
NIL returns 2+1 = 3,
Fib(4)
fills in F[4] with 3
3 2
NIL
4 3
NIL returns 1+1 = 2,
Fib(3)
5 5
NIL fills in F[3] with 2
returns 0+1 = 1,
Fib(2)
fills in F[2] with 1
F0 F1 F2 F3 … Fn-2 Fn-1 Fn
return F[n]
Can perform application-specific optimizations
e.g., save space by only keeping last two numbers
computed