Here is a Java interface description for a simple notion of a timer.
You should write a concrete class called StopWatch which implements this interface. You will need to know (of course) how to get the actual timings; you may find the code in this file (graciously supplied by Professor Orr) useful:
Timing.java
You should copy both of these files to your own directories, then create a project which has includes the Timer interface, your StopWatch class and some sort of main driving routine to test the StopWatch (see the next phase below for ideas).
For the next part of the lab, you should test out your StopWatch by using it to time some simple loops, keeping track of the results and presenting them in a table (rows might represent different loop limits, columns might represent different tasks). In particular, you should test all of the following tasks for loop limits of 100, 10,000 and 1,000,000 (but don't run any test that takes longer than a few minutes, i.e., don't waste time waiting too long):
When you are done gathering this information, write a short paragraph or two explaining what you found: were there any anomalies or unexplainable results?
Note: if you put all the blocks of code together for convenience, remember to "turn off" one block of code using comments before you "turn on" the next one.
Once you have run these basic tests, go back and try plotting out running times for the nested loop example for various numbers of iterations (you may use a drawing program, spreadsheet, statistical package or just graph paper). Try to determine what the shape of the curve is (linear, quadratic, cubic, etc.) and run further tests until you feel fairly confident about your answer.
The sorting programs written by Prof. Weiss can be found at this link:
DataStructures directoryYou will need all 4 of these Java files in order to compile the sorting code (i.e., MyInteger, Comparable, Sort and Random).
Once you are set to time some of Weiss' sort routines, run some tests sorting the same sizes of input using insertion sort, quicksort and one other sorting method of your choice. Use at least 4 sizes of input for each sorting algorithm (i.e., at least 12 runs all together). Record your timing data in a chart and write a short summary of what you found (which algorithm was best, which was worst, etc.). Try to characterize the behavior of the algorithms: are they linear, quadratic or something else?
A typical table of results might look something like this:
| Algorithm | N = 100 | N = 200 | N = 500 | N = 1,000 |
|---|---|---|---|---|
| Insertion Sort | nnn | nnn | nnn | nnn |
| Quicksort | nnn | nnn | nnn | nnn |
| Heap Sort | nnn | nnn | nnn | nnn |