r/programming • • May 19 '18

7 Steps to solve dynamic programming interview problems

http://blog.refdash.com/dynamic-programming-tutorial-example/
18 Upvotes

9 comments sorted by

View all comments

2

u/RaptorXP May 20 '18

What's the difference between dynamic programming and regular programming?

1

u/ehaliewicz May 20 '18

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.

1

u/juliusmusseau May 22 '18

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).