📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Consider the following Python code for calculating

    Fibonacci numbers using memoization:     memo = {}     def fib_memo(n):         if n             return n         if n in memo:             return memo[n]         result = fib_memo(n-1) + fib_memo(n-2)         memo[n] = result         return result     # Call: fib_memo(5)     What is the sequence of values stored in memo after fib_memo(5) completes?
    A {2: 1, 3: 2, 4: 3, 5: 5} Correct Answer Incorrect Answer
    B {1: 1, 2: 1, 3: 2, 4: 3, 5: 5} Correct Answer Incorrect Answer
    C {0: 0, 1: 1, 2: 1, 3: 2, 4: 3} Correct Answer Incorrect Answer
    D {5: 5} Correct Answer Incorrect Answer
    E {} (empty) Correct Answer Incorrect Answer

    Solution

    The correct answer is A

    Practice Next
    ask-question