This repository contains the most important questions of dynamic programming and variations of each question so that it becomes easy to identify which approach is to applied in the given question.
Dynamic Programming is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of subproblems, so that we do not have to re-compute them when needed later.
Recursion and dynamic programming (DP) are very depended terms. You can not learn DP without knowing recursion.
Before getting into the dynamic programming lets learn about recursion.
Recursion is a programming technique where programming function calls itself.
Every recursion functions consist of two parts.
- code to execute in the recursive function
- termination condition or base condition
Recursion is very useful when your programs need to be divided into multiple parts and output of the one part is depends on the output of the previous part.
Recursion risks to solve identical subproblems multiple times. This inefficiency is addressed and remedied by dynamic programming.