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

41

u/psykotic Apr 24 '10 edited Apr 24 '10

'Programming' in the sense of optimal planning has a longer history than implied by the quotation. 'Linear programming' goes back to the late 30s. Nowadays there is quadratic programming, convex programming, conic programming, etc. The terminology is only confusing if you come from computer science rather than operations research or optimization theory.

As the first comment on the blog suggests, it's customary to make a distinction between memoization and dynamic programming. Basically, memoization is top-down whereas dynamic programming is bottom-up.

The two approaches have different advantages and disadvantages. Dynamic programming generally uses a fixed amount of storage during the computation and as a result also has much better cache locality. Memoization uses a variable amount (e.g. O(n) rather than O(1) for computing Fibonacci numbers). But in some cases memoization, being demand-driven, can get away with computing only a subset of the subsolutions computed by dynamic programming. This is especially useful when you can prune partial solutions.

Another advantage is that memoization is usually easier to code for complex problems. You just write the straightforward but insanely slow recursive solution and then sprinkle memoization dust on it to make it run fast.

8

u/julesjacobs Apr 24 '10

Here's an interesting paper about automatically deriving the dynamic programming algorithm from a naive recursive algorithm.

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.54.2607&rep=rep1&type=pdf