Dynamic Programming is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the 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. This simple optimization reduces time complexities from exponential to polynomial.
Let’s discuss the basic dynamic programming concepts to solve problems effectively.
There are following two different ways to store the values so that the values of a sub-problem can be reused. Here, we are going to discuss the two patterns of solving the dynamic programming problem:
Tabulation
Tabulation is an approach also called Bottom-Up where you solve a dynamic programming problem by first filling up a table, and then computing the solution to the original problem based on the results in this table.
Memoization
Memoization is an optimization technique also called Top-Down used to speed up programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
#dynamic-programming #programming #java #fibonacci #algorithms #algorithms