Dynamic programming is more of a way to solve problems more than it is a style of programming. It’s basically a category of algorithms that caches intermediate results in order to reduce computation.
Dynamic programming is just a bad name. It generally refers to algorithms that break a program down into sub-problems, and reuses previous results as necessary.
I think of it more for breaking the problem into an optimal arrangement of sub-pairings, where any set of sub-pairings is possible, but only one specific arrangement of sub-pairings is optimal.
Matrix multiplication is the canonical example. If you have to multiply matrices A x B x C, it can be much cheaper to multiply (A x B) x C compared to A x (B x C) depending on the dimensions of the matrices. DP is a efficient technique for selecting the optimal positions for the parentheses in an example like that - or any other problem that can be broken down that way (e.g., divide & conquer, but where the divide points themselves matter).
2
u/RaptorXP May 20 '18
What's the difference between dynamic programming and regular programming?