# O(n^2) which is terrible def fibonacci(n): if n == 0 or n == 1: return 1 else: return fibonacci(n-1)+fibonacci(n-2) answers={0:1,1:1} # O(n) which is as good as it will get for Fibonacci. # Still takes up more stack space for the call stack # compared to an iterative approach. Also takes up extra # space for the dictionary itself. def fib(n): print(answers) if n in answers: return answers[n] else: value = fib(n-1)+fib(n-2) answers[n] = value return value