Introduction
What is Dynamic Programming?
Dynamic Programming (DP) is often considered one of the most challenging topics in computer science algorithms. However, at its core, it is simply an optimization technique.
The fundamental idea of DP is “Don’t Repeat Yourself.”
If you have already solved a sub-problem, you should save the result (cache it) so that you never have to calculate it again. By trading a little bit of space (to store results) for time (to avoid re-calculation), DP can turn an inefficient exponential algorithm ($O(2^n)$) into a highly efficient linear one ($O(n)$).