Data structure

Dynamic Programming Algorithm

Dynamic Programming Algorithm

Dynamic programming is also known as the memorization technique. Dynamic programming is a good approach because the idea about this is to store the previously calculated results to avoid the calculations again. In Dynamic Programming, complex problem is divided into subparts, and the result stores for further use. This simple optimization reduces time complexities from exponential to polynomial. 

Example: Matrix Chain Multiplication, Longest Common Subsequence, Travelling Salesman Problem, Fibonacci sequence

Fibonacci Sequence:

function fib(n)

        if n<=1 return n 

        return fib(n-1) + fib(n-2)

Explanation: In the above example of Fibonacci sequence, results which came from each subproblem are stored so that it could be used further.