Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can i please get help with question 4? Please send answer in a text format if possible. Problem 4. Let the function f(n) be defined
can i please get help with question 4? Please send answer in a text format if possible.
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
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