DFS and BFS

Problems content

Recursion of Memoization

Memoization of Fibonacci

The Python code is:

def fib(N):
    cache = {}
    def recur_fib(N):
        if N in cache:
            return cache[N]
        if N < 2:
            result = N
        else:
            result = recur_fib(N - 1) + recur_fib(N - 2)

        cache[N] = result
        return result
    return recur_fib(N)
Last Updated: 4/14/2019, 10:25:13 PM