# recursion.py # # Playing around with recursive functions. import matplotlib.pyplot as plt import time def fib(n): if n == 1 or n == 2: return 1 else: return fib(n-1) + fib(n-2) def fasterFib(n): """ Uses a memoized dictionary to keep track of intermediate results, speeding up the recursion. """ memo = {} return fasterFibHelper(n, memo) def fasterFibHelper(n, memo): """ If n is a key in memo, returns the stored result. Otherwise, computes fib(n) and stores the result in memo before returning it. """ return 0 # TODO def timeFib(): pass # TODO def main(): timeFib() if __name__ == "__main__": main()