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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started