Question
Revise the three programs given below (Example1.java, Example2.java, and Example3.java) to automatically (using a loop) print the run times for at least 6 equally spaced
Revise the three programs given below (Example1.java, Example2.java, and Example3.java) to automatically (using a loop) print the run times for at least 6 equally spaced N values. Choose N values such that all of the run times are more than 1 second. Note: The N values do not need to be the same for all of the algorithms. For example, you may use larger N values for faster algorithms and smaller N values for slower algorithms in order to have run times that are convenient for comparison.
Below is an example of how your output might appear for one of the algorithms:
Example1.java:
public class Example1 { public static void main(String[] args) { long startTime, stopTime; // For recording start/stop times long x = 0; startTime = System.currentTimeMillis(); for (long i = 0; i
Example2.java:
public class Example2 { public static void main(String[] args) { long startTime, stopTime; // For recording start/stop times long x = 0; long N = 30000L; startTime = System.currentTimeMillis(); for (long i = 0; i
Example3.java:
public class Example3 { public static void main(String[] args) { long startTime, stopTime; // For recording start/stop times long x = 0; long N = 30000L; startTime = System.currentTimeMillis(); for (long i = 0; i
Example #1 N-10000000, time-31 msec N 20000000, time = 110 msec N-30000000, time109 msec N - 40000000, time172 msec N 50000000, time = 203 msec 60000000, time 266 msec
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