Solved

The Following Fibonacci Function Calculates the Nth Fibonacci Number Recursively

Question 3

Multiple Choice

The following fibonacci function calculates the nth Fibonacci number recursively: In [1]: def fibonacci(n) :
) ..: if n in (0, 1) : # base cases
) ..: return n
) ..: else:
) ..: return fibonacci(n - 1) + fibonacci(n - 2)
) ..:
Which of the following statements is false?


A) Because fibonacci is a xe "recursion:recursive call"recursive function, all calls to fibonacci are recursive.
B) Each time you call fibonacci, it immediately tests for the xe "base case"base cases-n equal to 0 or n equal to 1, which the fibonacci function tests simply by checking whether n is in the tuple (0, 1) .
C) If a base case is detected, fibonacci simply returns n, because fibonacci(0) is 0 and fibonacci(1) is 1.
D) Interestingly, if n is greater than 1, the xe "recursion:recursion step"recursion step generates two recursive calls, each for a slightly smaller problem than the original call to fibonacci.

Correct Answer:

verifed

Verified

Related Questions