What is Dynamic programming?

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.

Basic Concepts of dynamic programming

  1. Tabulation and maximization
  2. Optimal substructure property
  3. Overlapping subproblem property
  4. How to solve a dynamic programming problem

1. Tabulation and memorization

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:

  1. Tabulation: Bottom Up
  2. Memoization: Top Down

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.

Image for post

#dynamic-programming #programming #java #fibonacci #algorithms #algorithms

Getting Started with dynamic programming
2.15 GEEK