write the algorithm for dynamic programming
Answers
Answer:
My Dynamic Programming Process
Step 1: Identify the sub-problem in words. ...
Step 2: Write out the sub-problem as a recurring mathematical decision. ...
Step 3: Solve the original problem using Steps 1 and 2. ...
Step 4: Determine the dimensions of the memoization array and the direction in which it should be filled.
Answer:
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. This simple optimization reduces time complexities from exponential to polynomial. For example, if we write simple recursive solution for Fibonacci Numbers, we get exponential time complexity and if we optimize it by storing solutions of subproblems, time complexity reduces to linear.