Lab 11 C++ Download the attached program and run it - as is. It will prompt for...

70.2K

Verified Solution

Question

Programming

Lab 11 C++

Download the attached program and run it - as is. It will promptfor a Fibonacci number then calculate the result using a recursivealgorithm. Enter a number less then 40 unless you want to wait fora very long time.

Find a number that takes between 10 and 20 seconds. (10,000 -20,000 milliseconds).

  1. Modify the program to use the static array of values to\"remember\" previous results. Then when the function is called againwith the same value, simply return the value. You might think ofthis as the number of base cases expanding dynamically as theprogram runs.
/* * CS 1337 Lab Assignment 11 * * Dynamic Programming Example * * Use dynamic programming do make the Fib() function more usable for large * values of n. This program has a timer that will calculate the time it * takes to run the function. Use that to compare the before and after times. * */#include #include #include // ...using namespace std::chrono;milliseconds get_time() {  milliseconds ms = duration_cast< milliseconds >(    system_clock::now().time_since_epoch()  );  return ms;}using namespace std;int Fib(int n) {  // Keep track of calculated values in a static array.   static int values[100] = {0};   int retval;    // base cases.   if (n<=0) return 0;  if (n==1) return 1;   retval = Fib(n-1) + Fib(n-2);   return retval;}/* * */int main(int argc, char** argv) {    int val, n;  duration time_span;  high_resolution_clock::time_point start, end;     cout << \"Enter a number less the 100: \";   cin >> n;  start = high_resolution_clock::now();  val = Fib(n);  end = high_resolution_clock::now();  time_span = end - start;  cout << \"Fib(\" << n << \") is : \" << val << endl;  cout << \"Elapsed time in milliseconds: \" << time_span.count() << endl;  return 0;}

Answer & Explanation Solved by verified expert
3.8 Ratings (674 Votes)
do comment if any problem arises code CS 1337 Lab Assignment 11 Dynamic Programming Example Use dynamic programming do make the Fib function more usablefor    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students