Question: Casey's program: def a (n): if n== 0: return 0 elif n==1: return 1 else: return a (n-1) + 2*a (n-2) for n in range

Casey's program: def a (n): if n== 0: return 0 elif n==1: return 1 else: return a (n-1) + 2*a (n-2) for n in range (2, 101): print (n, a (n)) Counting the number of arithmetic operations Casey's program must perform is a little more difficult. Let's introduce the notations N(n) for the number of arithmetic operations Casey's function a(n) must perform to compute just an, and S(m) for the number of arithmetic operations Casey's entire program would have to perform to compute all the sequence terms from a2 up to am, if the number 101 in the program was replaced by m+1. Observe that S(m) is the sum of the N(k) from k = 2 to m, and that S(100) is the total number of arithmetic operations Casey's program as given has to perform. Find the recurrence relation that expresses N(n) in terms of N(n - 1) and N(n - 2) and explain. [You should get a recurrence relation that closely resembles that of the Fibonacci sequence.] We cannot find a closed form solution for N(n) directly using the technique we learned in class for linear, constant-coefficient homogeneous recurrence relations due to the presence of a constant term in the recurrence relation for N(n). Use the following workaround: Instead of solving for N(n). solve for Q(n) = N(n) + 2. i. rewrite the recurrence relation of N(n) in terms of Q(n). ii. find the closed-form solution for Q(n). iii. use that to find the closed-form solution for N(n)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
