The goal of this lab is to study the efficiency of sorting algorithms experimentally and to compare the results with the theoretical findings of complexity analysis.
Make a directory for this lab. Copy the lot of sorting algorithms and helper programs from the course directory:
cp /homes/tvandrun/Public/cs245/lab2/* .
You have the following tools/pieces at your disposal for use in the experiments assigned below.
SortUtil
, a class that contains public methods
createRandomArray()
, createRandomList()
,
displayArray()
, and displayList()
.
System.currentTimeMillis()
,
which reads from the the system clock to determine the current time
(represented by the number of milliseconds that have elapsed since
midnight, January 1, 1970).
By calling this method before and after a piece of code, you
can determine the number of milliseconds that have elapsed
while a piece of code runs.
The return type of the method is long
, not
int
, so keep that in mind for storing results in
variables.
For more information on this method,
see the Java API reference.
Read all of the experimental questions below. Then pick two of them to experiment on (if you have time left over, then pick a third, just for fun). Write programs to conduct experiments to answer the questions. Write programs that actually automate the experiment. For example, if you decided to run selection sort on 10 arrays for each size 10, 50, 100, 500, 1000, and 5000, you might write something like
int[] sizes = {10, 50, 100, 500, 1000, 5000}; for (int i = 0; i < sizes.length; i++) for (int j = 0; j < 10; j++) { int[] array = SortUtil.createRandomArray(sizes[i]); SelectionArray.sort(array); }
Use your program also to do things like calculate averages and high/low and generate tables, where appropriate.
For each experiment, turn in your code and a brief (paragraph-sized) write up of your methodology, results, and conclusions. Include a table and/or (if you think it illustrates the case for your conclusions) a graph.