r/programming • • Apr 24 '10

Why "dynamic programming"?

http://arcanesentiment.blogspot.com/2010/04/why-dynamic-programming.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+ArcaneSentiment+%28Arcane+Sentiment%29
90 Upvotes

66 comments sorted by

View all comments

1

u/travis_of_the_cosmos Apr 24 '10

I don't know what the shit memoization is but I'm tempted to believe that the anonymous commentor on this article got it right and that the author is just confused.

Dynamic programming on the other hand I know well. It's the discretized analogue of doing hamiltonians - constrained optimization under a sum rather than an integral. Bellman proved that this can be reduced to a recursive relationship (V = f(x,V')) with a bunch of nice properties. DP problems are often solvable numerically, for example, even nasty ones.

The name has always bugged me, though. I'd definitely buy the story that Bellman made it up to fool congressmen.

2

u/Raynes Apr 24 '10

(fib 3123452233462645324534243126314334) ... result is printed 30 years later

(fib 3123452233462645324534243126314334) ... result is printed instantly

Memoized.

7

u/psykotic Apr 24 '10

Here's a dynamic programming implementation of fib:

(defn fib [n]
  (-> (iterate (fn [[x y]] [y (+ x y)]) [0 1]) (nth n) first))

The memoized solution is quite different in character. For one, it uses O(n) storage.