Question: ECCE 4 2 5 7 Lab 1 2 - Write a function fibonacci _ recursive ( n ) that calculates the nth Fibonacci number using
ECCE
Lab
Write a function fibonaccirecursiven that calculates the nth Fibonacci number using recursion. Then, write another function, fibonacciiterativen that calculates the nth Fibonacci number using an iterative loop.
a Verify the correctness of your implementations by calculating the first Fibonacci numbers with both functions and comparing their outputs.
b Measure the execution time of both your recursive and iterative functions for increasing values of and increase by until you reach
c Summarize the key differences between the recursive and iterative approaches to computing Fibonacci numbers in terms of their efficiency.
Use the following starter
import time
for in range :
starttime time.time
fibonacci recursiven
print Recursive for : timetimestarttime:. : seconds"
start time time.time
fibonacci iterativen
print Iterative for : timetime starttime: : seconds"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
