r/programming • u/FollowSteph • May 19 '18
7 Steps to solve dynamic programming interview problems
http://blog.refdash.com/dynamic-programming-tutorial-example/4
2
u/RaptorXP May 20 '18
What's the difference between dynamic programming and regular programming?
11
u/jasquebie May 20 '18
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.
3
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).
2
May 20 '18
I like the article , but it can be a bit hard to read and keep a straight face when the acronym is DP
2
9
u/juliusmusseau May 20 '18
DP was my kryptonite in algs class. I think I'll stick with my current job until this fad passes...
(Unless interview permits "sit with algs textbook for 2 hours"!)