Answered step by step
Verified Expert Solution
Question
1 Approved Answer
0. Iteration vs Recursion fibonacci.py In this exercise, we will explore the performance of iteration versus recursion. Recall that the Fibonacci number n for n
0. Iteration vs Recursion fibonacci.py In this exercise, we will explore the performance of iteration versus recursion. Recall that the Fibonacci number n for n > 0 is defined as F = Fn-1 + F1-2 with Fo= 0 and F1 = 1. In fibonacci.py, code is provided for you that times how long it takes to run a function that computes F. iteratively and recursively. (a) First fill in the function fib_recur(n) that computes the Fibonacci number recursively. (b) Next fill in the function fib_iter (n) to compute the Fibonacci number iteratively, rather than recursively. Make sure it has the same output as fib_recur. (c) Call fib_iter and fib_recur for n = 5,10,20,30, and compare their runtimes. What do you see? Which one is slower? What are the pros and cons of iterative vs. recursive solutions? 1. Exponential exponential.py Write a recursive function exponential (base, exp) that calculates base ** exp without using the operator, just as we did in ps3, but this time with recursion instead of an iterative for loop. This time, you can focus on positive exponents only. 2. Member member.py Write a recursive function member (1tem, my_11st) that returns True if item is in my list, and False if not, without using the in operator, but you may use the operator. Hint: You will probably want to have two base cases--one that handles the case where the list is empty, and another that checks for the presence of the item in the current list.
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