Memoizing Fibonacci Numbers

In this lesson, we are going to reduce the time complexity of the Fibonacci code we wrote using a dynamic programming technique called memoization.

Let’s memoize the code now and see where that leads us. The basic idea is to check if a list already contains the result of the Fibonacci number that we are trying to find before calculating it.

Memoized code

Have a look at the complete code in Python:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.