Question: C++ Exercise 3: Run the following given code and plot number of iterations represented by the returned value (count1 or count2) vs. n. Observe the

C++

Exercise 3:

Run the following given code and plot number of iterations represented by the returned value (count1 or count2) vs. n.

Observe the difference between n^2 and n log n.

#include #include using namespace std; int count1(int n) { int temp = 0; for (int i = 1; i <= n; ++i) for (int j =1; j <= i; ++j) ++temp; return temp; } int count2(int n) { int temp = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; j*=2) ++temp; return temp; } int main() { for (int i = 1; i <= 16384; i = i * 2) cout << count1(i) << " "; cout << endl; for (int i = 1; i <= 16384; i = i * 2) cout << count2(i) << " "; cout << endl; }

Please use excel to plot the graph

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!