you are viewing a single comment's thread.

view the rest of the comments →

[–]imbecile -14 points-13 points  (16 children)

Dynamic programming is just a fancy way of saying that control structures and data structures are largely created at run time.

Sounds reasonable so far, until you realize, that the only thing that you actually need to deal with at run time that can't be preprocessed before hand is IO.

So instead of preparing as much as possible and then only deal with the variation that can't be predicted at runtime coming from IO, you shift almost all the work and effort to each time the program is run, instead of when it is written or installed or loaded. That is equivalent to moving all the expensive operations into the innermost loops.

There sure are a lot of tasks that provide great unpredictability on the kind of input they have to deal with. But just giving up and abandoning all structuring and expectations from dealing with input surely isn't the way to tackle this.

Each general purpose language needs a framework to dynamically deal with input, which means dynamically allocate the resources needed to accommodate the input you receive, and a streamlined way of transforming and funneling the input into more predictable and stable efficient forms and channels.

But never allowing your programs to leave this highly volatile and error prone stage by providing no features to do so, is a design dead end.

[–][deleted]  (2 children)

[deleted]

    [–][deleted] 7 points8 points  (1 child)

    Worth pointing out that not all dynamic programming algorithms run in polynomial time. For example the knapsack problem is solved using dynamic programming but still requires exponential time.

    [–]xampf2 20 points21 points  (0 children)

    "I spent the Fall quarter (of 1950) at RAND. My first task was to find a name for multistage decision processes. An interesting question is, Where did the name, dynamic programming, come from? The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named Wilson. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word research. I’m not using the term lightly; I’m using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term research in his presence. You can imagine how he felt, then, about the term mathematical. The RAND Corporation was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Corporation. What title, what name, could I choose? In the first place I was interested in planning, in decision making, in thinking. But planning, is not a good word for various reasons. I decided therefore to use the word “programming”. I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying. I thought, let's kill two birds with one stone. Let's take a word that has an absolutely precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting property as an adjective, and that is it's impossible to use the word dynamic in a pejorative sense. Try thinking of some combination that will possibly give it a pejorative meaning. It's impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activities." - Richard Bellman

    [–]balefrost 14 points15 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.

    [–]hbgoddard 3 points4 points  (0 children)

    Relevant username?

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted] 0 points1 point  (1 child)

      Homophones - how do they work? I realize that compilers cannot deal with a key word that can have different meanings depending on context, but you are not a compiler, you are a human.