| Learn | Algorithm - Applications of Dynamic Programming - Fibonacci numbers |
|---|
| Fibonacci Numbers Fibonacci Numbers (opens new window) are a prime subject for dynamic programming as the traditional recursive approach makes a lot of repeated calculations. In these examples I will be using the base case of Here is an example recursive tree for Non-Dynamic Programming This is the most intuitive way to write the problem. At most the stack space will be The Memoized With the memoized approach we introduce an array that can be thought of as all the previous function calls. The location Iterative Dynamic Programming If we break the problem down into it's core elements you will notice that in order to compute With this information, it now makes sense to compute the solution backwards, starting at the base cases and working upwards. Now in order to calculate This main benefit here is that we now have eliminated the recursive stack while keeping the Advanced Iterative Dynamic Programming As noted above, the iterative dynamic programming approach starts from the base cases and works to the end result. The key observation to make in order to get to the space complexity to To store these last 2 results I use an array of size 2 and simply flip which index I am assigning to by using I add both indexes of the array together because we know that addition is commutative ( NotesRemarksDefinitionsMemoization (opens new window) - an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again. Dynamic Programming (opens new window) - a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions. |
Read Article
https://develop.horje.com/learn/1434/reference