Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy the program code presented below and save it as PerformanceTest.java. Then, complete the following: a. Compile the program and fix any syntax problem if

Copy the program code presented below and save it as PerformanceTest.java. Then, complete the following:

a. Compile the program and fix any syntax problem if theres any so that it can be executed.

b. State what sum1 and sum2 in the program try to calculate writing a math expression to show the calculation is OK.

c. State the program's functionality (what does its output mean?)

d. Run it at least 3 times and do a screenshot for each execution including the output and copy it in your answer document (your submission must have at least 3 screenshots).

e. Compare the results you received from all three runs, are the printouts the same? If not, what could be the reason for the differences?

f. The above activities can be considered as an experiment to compare the runtimes for an algorithm. Based on your observation, do you think empirical comparison is a reliable approach for comparing algorithm performances? Why or why not?

Code:

import java.lang.Math;

public class PerformanceTest{

public static void main(String [] args){

int n = 10;

int sum1, sum2;

int i;

int j;

//1st segement

for (n=1; n<= 1000000; n*=10){

sum1 = 0;

long startTime = System.nanoTime();

for (i = n; i>=1; i--)

for (j = 1; j<=100; j++)

sum1++;

long estimatedTime = System.nanoTime() - startTime;

System.out.print("[n="+ n + "]");

System.out.print("estimated time for the 1st program segment is: ");

System.out.println(estimatedTime);

}

//2nd segment

for (n=1; n<= 1000000; n*=10){

sum2 = 0;

long startTime = System.nanoTime();

for (i = 1; i< Math.pow(2,n); i=i*2)

sum2=sum2+i;

long estimatedTime = System.nanoTime() - startTime;

System.out.print("[n="+ n + "]");

System.out.print("estimated time for the 2nd program segment is: ");

System.out.println(estimatedTime);

}

}

}

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

outline some of the current issues facing HR managers

Answered: 1 week ago