Embercode
✕
Dynamic ProgrammingQuick quiz

Fibonacci and decode ways

8 questions. Covers Decode ways and string partition DP in Python.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python def fib(n): a, b = 0, 1 for _ in range(n): a, b = b, a + b return b print(fib(5)) ``
  2. 2. What does this program print? The second number is the count of calls. ``python calls = 0 def fib_naive(n): global calls calls += 1 if n < 2: return n return fib_naive(n - 1) + fib_naive(n - 2) f = fib_naive(6) print(f, calls) ``
  3. 3. In the matrix method, matrix_power(M, p) with M = [1 1; 1 0] and p = 8 calls multiply for each squaring of base and for each multiplication into result. How many calls to multiply are made in total?

    Type a number.

  4. 4. Which statements about the matrix method for F(n) are true? Select all that apply.

    Pick every answer that is true.

  5. 5. After the loop in fib(n) finishes, what do a and b hold?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.