Question
Algorithm Analysis question, please answer all the question Submit your code and screenshot of it performing the calculations along with results, see submission notes below
Algorithm Analysis question, please answer all the question
Submit your code and screenshot of it performing the calculations along with results, see submission notes below regarding submitting code:
Implement the following pseudocode functions (in C#, C/C++, Python or Java - if other language let me know in advance) and provide the results for each of the n in the table below.
n = { 2, 10, 100, 1000, 10000}
Function I:
for( double i = 0.0; i < lg(n); ++i) {
sum += i;
++count;
}
cout << for n = << n << : count = << count << endl;
Function II:
for( double i = 0.0; i < n2; ++i) {
sum += i;
++count;
}
cout << for n = << n << : count = << count << endl;
Function III:
for( double i = 0.0; i < 1.002n; ++i) {
sum += i;
++count;
}
cout << for n = << n << : count = << count << endl;
Final count result for:
Function | n = 2 | n = 10 | n = 100 | n = 1000 | n = 10000 |
I lg(n) |
|
|
|
|
|
II n2 |
|
|
|
|
|
III 1.002n |
|
|
|
|
|
What do you observe for each function as n gets larger?
If you change n = 1.02 to n = 1.03 what do you observe (may want to estimate loopcount before and printing values before looping 1.02n / 1.03n)?
Note: If implemented correctly no loop should take much longer than 30 seconds to complete for n = 1.02 on any CPU in Ghz range. Make sure you know your IDEs abort (e.g. Ctrl-C).
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