Download the lab13 folder from the download directory.
Notice that it contains a javafoundations folder with a Queue implementation.
It also contains the Sorting.java file that implements several famous sorting algorithms: RadixSort
, InsertionSort
, SelectionSort
, MergeSort
, QuickSort
.
We will generate data of various sizes randomly and have each algorithm run on the same unsorted set of data, so that the comparison makes sense. We will use an array to hold and sort the data.
You should be able to compile the Sorting.java file and see how it reports its results. Examine carefully the main() method because you will need to use a more involved version in the next step to run and record your experiments.
In this task you will create a new class the class SortingComparison.java, that will produce a table of values as shown below:
Sorting integers: Time in seconds
#ints RadixSort Selection Insertion MergeSort QuickSort
10000
20000
30000
...
90000
100000
Take a look at some Visualizations of Sorting Algorithms to get a sense on how these algorithms manage to sort their input!
With the members of your team try to answer the following questions as best as you can:
Beware that you cannot really answer all of these questions with just experiments. You will need some deeper understanding on how they work and why. Take CS231 to learn more!
Obama is known primarily for his opinion regarding BubbleSort
.
Was he right?
If you still have time, run similar experiments with the HeapSort algorithm that we encountered at a previous lab and see how its running times compare with the ones we run here.