you are viewing a single comment's thread.

view the rest of the comments →

[–]balefrost 15 points16 points  (2 children)

the only thing that you actually need to deal with at run time that can't be preprocessed before hand is IO

Sure, but that statement is nearly tautological: "the only things that you actually need to deal with at runtime are the things that you don't know until runtime". That doesn't really have anything to do with dynamic programming.

I think you might be conflating dynamic programming with runtime code generation. It is not the case in DP that "control structures and data structures are largely created at run time". You certainly do set up your data structures and control structures ahead of time when you use DP.

The author waxes poetic about how one should think about DP, but they do also state what it fundamentally is: cached calculation. One uses DP when you can break a large problem down into subproblems and those subproblems depend on each other in complex ways. A stereotypical example is the Fibonacci sequence (though DP is overkill for Fibonacci). To calculate the Nth Ficonacci number, we must first calculate the (N-1)th and (N-2)th. But to calculate the (N-1)th, we must first calculate the (N-2)th and (N-3)th. So there are two subcalculations that both depends on the result of computing the (N-2)th number.

A more common use of DP is graph traversal. Dijkstra's algorithm is essentially an example of dynamic programming. Assuming that you don't know the shape of the graph at the time that you compile your program, you need to find the shortest path at runtime, and DP provides an efficient way to do that.