Objective
Create a Python program that computes the Fibonacci number in two ways and compares how many calls each one makes. The simple recursive version is exponential; with memoization (storing already computed results) it becomes linear.
Instructions
- Read an integer
n(between 0 and 25). - Write
fib_simple(n), which counts every call and usesfib(n-1) + fib(n-2)(withfib(0)= 0 andfib(1)= 1). - Write
fib_memo(n)the same way, but with a dictionarymemo: count every call (even those answered from the dictionary) and, before computing, return the stored result if it already exists. - Show
Fibonacci(n) = v,Calls without memoization: xandCalls with memoization: y.
10
Fibonacci(10) = 55
Calls without memoization: 177
Calls with memoization: 19
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise