Question: The Fibonacci sequence is a famous sequence in which each term is the sum of the two preceding ones. The nth Fibonacci number denoted F(n)

The Fibonacci sequence is a famous sequence in which each term is the sum of the two preceding ones. The nth Fibonacci number denoted F(n) is given by the recurrence relation: F(n) = F(n 1) + F(n 2), for n = 2, 3, . . . with initial conditions (i.e. base cases) F(0) = 0 and F(1) = 1.

For instance: F(2) =F(2 1) + F(2 2) = F(1) + F(0) = 1 + 0 = 1and F(3) =F(3 1) + F(3 2) = F(2) + F(1) = 1 + 1 = 2.

TODO: 1. Write a Python function Fibnorecursion(n), which takes an integer n as input and returns the nth Fibonacci numbers (1). Your code must contain a for loop and should not use recursion. 2. Write a Python function Fibrecursion(n), which takes an integer n as input and returns the nth Fibonacci numbers (1). Your code must use recursions and should not use for loops.

Hint: Make sure to cover the base cases n = 0 and n = 1. Use the unit tests given in the Jupiter notebook to verify that your routines Fibnorecursion and Fibrecursion are working properly. You are not allowed to modify the unit tests

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!