Timing execution of function of various run-times

I have started the program but I am stuck. I am having trouble trying to get the output to work. I know that I have to get a for loop to get the methods to run but I have no idea how to implement it.

If anyone knows how to do this can you help?

The instructions of what is expected with the program and preferred output:

Write a Java program that times the executions of function of various run-times. Read this discussion to learn how to time individual methods.
Your program must have methods of O(log n), O(n), O(n log n), and O(n2) run times. The methods cannot be static since they will share the same n, which will be passed to a constructor.
In a test driver, create an instance of your timings object for a small value of n, say 100. Gather timings for each of your methods. Then increase n by a factor of 10 and again gather timings. Note that this can be easily done by initializing n to 100 and then, in a loop, have each iteration should a new instance and then call each function and then multiply n by 10.
None of the methods, other than the constructor, should take any arguments. All each should need is a value for n, and since this value is a data member within the object directly available to all methods..
How does your program terminate? The loop condition should become false when the slowest method consumes more than one minute.
What should your output look like? Consider the following example (with entirely fictional numbers). All numbers will be double, and we need not be concerned about the number of decimal places.
n = 100
O(log n): 0.4 seconds
O(n): 0.3 seconds
O(n log n): 0.2 seconds
O(n^2): 0.1 seconds

n = 1000
O(log n): 1.2 seconds
O(n): 3.0 seconds
O(n log n): 6.0 seconds
O(n^2): 10 seconds

n = 10000
O(log n): 3.6 seconds
O(n): 30.0 seconds
O(n log n): 180.0 seconds
O(n^2): 1000.0 seconds

Execution would continue until the slowest algorithm consumes at least one minute. Format your output as above to ease the grader's pain.
You may end up using large values of n. Do not use useful algorithms where the amount of memory grows with n.
Possible Hardship
Suppose your O(n2) method is running for over five minutes. Make certain that your output clearly shows the current value of n and the times of the quicker methods, Then go ahead and kill the program, and write a note explaining that you killed it and provide an estimate of how long you believe you would have had to wait to obtain the run-time.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!