Expert Answer
1. Fibonacci series:a. Binary Recursion (slow):Binary recursion is used to calculate the nth number in the Fibonacci sequence. Starting with 0 and 1, the Fibonacci sequence is a set of numbers where each number is the sum of the two before it.The first test of the approach is if n is less than or equal to 1. If so, it returns n because it is the recursion's base case. If not, it repeats the process for n-1 and n-2 and provides the total of the two outcomes. This method of binary recursion is less effective because it might exponentially increase the number of function calls and dramatically slow performance for high values of n.For example, if n is equal to 2, it takes the sum of the [ 0, 1 ] i.e 0+1, and the result (1) is the nth Fibonacci number. Similarly, if is equal to 3, [0, 1, 1 ] the last two numbers 1+1 will be the result.b. linear recursion (fast):Computing the n-th number in the Fibonacci sequence using linear recursion.The nth number in the Fibonacci sequence is determined by the approach using linear recursion. It initially verifies whether n is 0 or 1. If so, since it is the base case of the recursion, it returns the matching value of prev1 or prev2. If not, it repeatedly invokes the same function using prev2 and prev1+prev2 as the new values for prev1 and prev2, respectively, and n-1 as the new index. By adding the two numbers before it, the approach builds up the series one step at a time until it reaches the n-th number.This linear recursion method is quicker and less memory-intensive than the binary recursion method since it only uses two function calls per recursive step.c. Iterative (fast):The function determines whether n is less than or equal to 1 in the first step. If it is, n is directly returned as the nth Fibonacci number. If not, the function initializes prev1, prev2, and curr, three variables.Since prev1 represents the (n-2)th Fibonacci number, it is set to 0. The value of prev2 is set to 1, which is the (n-1)th Fibonacci number. Since the current (n)th Fibonacci number will be stored in curr during the loop, it is initially set to 0.The function then starts a for loop and iterates up to n times, starting at 2. Prev1 and Prev2 are added to curr during each cycle. The (n-1)th Fibonacci number for the following iteration, prev2, is then updated from prev1, which was the previous version. The current (n)th Fibonacci number, curr, is updated from prev2 to represent it.The function then returns curr, which is the nth Fibonacci number, at the end of the loop.