2. Fibonacci - 2 #

Created Monday 09 March 2020

This code is the 3rd approach:


Things to note, jargon:

So the three approaches are:

  1. Bruteforce: Unoptimized code. Laziest solution.
  2. Memoization - Top-down approach

We try to solve the largest problem first, but if it is not solved yet, we solve it’s dependencies. This continues until we reach a point where the base case values are present. From there start the returning phase of the recursion, where we solve all the problems to finally solve our required task. We try to solve the hardest problem first, hence this is called a top-down approach.

  1. Dynamic Programming - Bottom-up approach

We try to explicitly solve all the dependencies first, then we try to solve the harder problems, till we reach the required problem. Which can be solved as all previous ones have now been solved.

Problem solving strategy: We first write the naive recursive solution. Then we write the memoized approach. Then we refine it to DP by dependency analysis. We have to follow this now, until we develop the skill to directly write DP solutions. Don’t solve in one go, as this stops the learning process.