Question: The program Example4.java (given below) uses Math.log() to compute the N value for the algorithm, and the expected Big-O time is O(log N). Can you

The program Example4.java (given below) uses Math.log() to compute the N value for the algorithm, and the expected Big-O time is O(log N). Can you find an N value that results in an experimental run time that is greater than 0 msec? If you could run an experiment using this algorithm, using non-zero run times, how would you expect the graph to look?

public class Example4 { public static void main(String[] args) { long startTime, stopTime; // For recording start/stop times long x = 0; long N = 10000000L; startTime = System.currentTimeMillis(); for (long i = 0; i < Math.log(N); i++) { x = x + 1; } stopTime = System.currentTimeMillis(); System.out.println(stopTime - startTime + " msec"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!