PROGRAMMING PROBLEMS For the following programming problems, you need to time a section of code in C++. For example, the following statements time the execution of the function doSomething: #include...


PROGRAMMING PROBLEMS<br>For the following programming problems, you need to time a section of code in C++. For example, the<br>following statements time the execution of the function doSomething:<br>#include <ctime><br>clock_t start = clock();<br>doSomething ();<br>clock_t finish = clock();<br>double overallTime = static_cast<double> (finish - start) / CLOCKS_PER_SEC;3<br>1. Consider the following two loops:<br>// Loop A<br>for (i = 1; i = n; i++)<br>for (j = 1; j e 10000; j++)<br>sum = sum + j;<br>// Loop B<br>for (i = 1; i <= n; i++)<br>for (j = 1; j <= n; j++)<br>sum = sum + j;<br>What is the Big O ofeach loop? Design and implement an experiment to find a value of n for which Loop B is<br>faster than Loop A.<br>2. Repeat the previous project, but use the following for Loop B:<br>// Loop B<br>for (i = 1; i <= n; i++)<br>for (j = 1; j <= n; j++)<br>for (k = 1; k <= j; k++)<br>sum = sum + k;<br>3 CLOCKS_PER_SECOND is a C++ predefined constant.<br>

Extracted text: PROGRAMMING PROBLEMS For the following programming problems, you need to time a section of code in C++. For example, the following statements time the execution of the function doSomething: #include clock_t start = clock(); doSomething (); clock_t finish = clock(); double overallTime = static_cast (finish - start) / CLOCKS_PER_SEC;3 1. Consider the following two loops: // Loop A for (i = 1; i = n; i++) for (j = 1; j e 10000; j++) sum = sum + j; // Loop B for (i = 1; i <= n;="" i++)="" for="" (j="1;" j=""><= n;="" j++)="" sum="sum" +="" j;="" what="" is="" the="" big="" o="" ofeach="" loop?="" design="" and="" implement="" an="" experiment="" to="" find="" a="" value="" of="" n="" for="" which="" loop="" b="" is="" faster="" than="" loop="" a.="" 2.="" repeat="" the="" previous="" project,="" but="" use="" the="" following="" for="" loop="" b:="" loop="" b="" for="" (i="1;" i=""><= n;="" i++)="" for="" (j="1;" j=""><= n;="" j++)="" for="" (k="1;" k=""><= j;="" k++)="" sum="sum" +="" k;="" 3="" clocks_per_second="" is="" a="" c++="" predefined="">

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here