The purpose of this question is to allow the student to independently compare the run time of various sorting and searching algorithms. This will allow the student to get a better understanding of time complexity. It also aims to build an appreciation of the effects that the size and organization of data have on the speed of algorithms.
The sorting algorithms that will be examined are:
All sorting algorithms must sort the arrays in descending order.
Each sorting and searching algorithm will be comparatively run on arrays of the following sizes:
Each sort and search is to be tested on the same data set to strive for some consistency.
Sorting Methodology and Requirements:
All recorded times must be measured using System.nanoTime() for consistency. An example of how to use it is given below.
long start = System.nanoTime();
//code to be tested
long end = System.nanoTime();
long timeTaken = end – start;
The unit for printing the time must be done according to the following table:
Test data size |
Time unit |
50 |
nanoseconds |
1,000 |
nanoseconds |
10,000 |
nanoseconds |
100,000 |
nanoseconds |
1,000,000 |
milliseconds |
Output requirements:
The name of each sorting algorithm tested and the time it took to sort the data must be shown grouped by the test data size. For example if the test data size is fifty (50), the time taken for all the sorting algorithms to sort the data must be shown one after another.