Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

Students also viewed these Databases questions

Question

Prepare a classified balance sheet

Answered: 1 week ago