Answered step by step
Verified Expert Solution
Link Copied!

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
sum++;
StdOut.println(sum);
image text in transcribed
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

Students also viewed these Databases questions

Question

=+Define social listening and social monitoring

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago