Question: Problem 4. Let the function f(n) be defined as f(0) = 0, (1) = 1, f(n) = f(n-1) + f(n- 2))(mod 331) for all n

 Problem 4. Let the function f(n) be defined as f(0) =

Problem 4. Let the function f(n) be defined as f(0) = 0, (1) = 1, f(n) = f(n-1) + f(n- 2))(mod 331) for all n > 1, where a mod b) is the remainder when a is divided by b (for example, 15(mod 6) = 3 since 15 = 2 x 6+3). Write a C++ program to implement the function : 1. It follows the recursion f(n) = f(n-1) + f(n-2))(mod 331) to compute f(n). ii. It computes f(n) without recursive call. iii. Test each implementation at n = 20,30,40,50, 100, 10000, and 100000 iv. Explain the difference between test results of the two implementations from the compiler and algorithm complexity point of view. We give an example to compute function (n) = 1+2+: n with two different implementations in C4+. The first uses recursion that function () calls itself, but the second does not use recursion int s(int n) if(n==1) {return 1;} else {return s(n-1)+n:) int s(int n) int sum=0; for (int i ;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!