In this assignment you will write a program that tests 4 different sorting algorithms: Bubble, Selection, Insertion, and Merge sort. You will write a Stopwatch class that uses System.nanotime() to measure the time each algorithm takes to sort 1000, 2000, 4000, and 8000 integers.
- Fork and clone down this repository.
- Run the program. You should see the following output:
Testing Bubble Sort
Bubble Sort took 0 microseconds
Testing Selection Sort
Selection Sort took 0 microseconds
Testing Insertion Sort
Insertion Sort took 0 microseconds
Testing Merge Sort
Merge Sort took 0 microseconds - First, use
System.nanotime()
to complete theStopwatch
class - Then, starting with
bubblesort
, complete the 4 sorting functions in theSorts
class` - (Note that you do not need to add any code to the
SortStep
program) - Test each sorting algorithm for the time it takes to sort 1000, 2000, 4000 and 8000 integers, and write your answers on the handout for the assignment. You should run the tests several times and record the best time for each.
- When you are finished, submit the sorting handout to the schoolloop drop box. (Note that is not necessary to submit your code for the assignment).
- If you have extra time, you might try to improve the efficiency of your merge sort. Also, feel free to add other sorts like quick sort or gnome sort to the program.