Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. In this exercise you will again experimentally determine the cost of several algorithms in terms of their input size. Note than in all the
2. In this exercise you will again experimentally determine the cost of several algorithms in terms of their input size. Note than in all the cases below, the cost is measured by counting the number of times we execute the body of the innermost loop and this is simply the value of the variable: sum.
Create a Java program for each algorithm and run the program for the input values shown, completing a table as shown below. Then plot the data using graphing software. The deliverable is:
the completed table
graph
The answer to the question (see page 1).
N
sum
1000
2000
4000
8000
16000
Algorithms to evaluate:
A)
N = StdIn.readInt();
int sum = 0;
for (int i =1; i
for (int j = 1; j
sum++;
StdOut.println(sum);
B)
N = StdIn.readInt();
int sum = 0;
for (int i =1; i
for (int j = 1; j
sum++;
StdOut.println(sum);
C)
N = StdIn.readInt();
int sum = 0;
for (int i = N; i > 0; i = i/2 )
for (int j = 1; j
2. In this exercise you will again experimentally determine the cost of several algorithms in terms of their input "size". Note than in all the cases below, the cost is measured by counting the number of times we execute the body of the innermost loop and this is simply the value of the variable: sum. Create a Java program for each algorithm and run the program for the input values shown, completing a table as shown below. Then plot the data using graphing software. The deliverable is: the completed table graph The answer to the question (see page 1). 1000 2000 4000 8000 10000 Algorithms to evaluate: A) N = StdIn.readInt(); int sum = 0; for (int i =1; i 0; i = i/2) for (int j = 1; j 0; i = i/2) for (int j = 1; j sum++;
StdOut.println(sum);
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