To compare the performance of the bubble sort and merge sort algorithms.
For this lab, you will write some code to test the actual runtime of bubble sort and
merge sort for large input sizes. You should create randomly filled arrays of various
sizes, sort them with each method, and calculate the time taken with each method.
- Start by downloading the SortComparison.java file which
contains functions to merge sort and bubble sort array arguments.
- Next write a function called "testSort" which will take an integer argument N, and
a second argument indicating which sort should be tested.
- Inside this function, you should create an array of size N, fill it with random
data, and then call one of the two sort functions based on the second argument.
- You should save current time on either side of the call to sort. Recall that
this can be done by calling new Date().getTime() which returns the number
of milliseconds since 1970.
- Using these values, calculate the elapsed seconds that the sorting function took
to run and return that.
- In your main function, call testSort for each of the two sorting algorithms
with the values 7500, 15000, 22500, 30000, 37500, 45000, 52500, 60000, 67500, and 75000.
That should be 20 total calls.
- Print the results in main for each test.
When your program works, email the code to firstname.lastname@example.org.
In the body of the email, paste the output of your program, which should show the performance
difference between the two sorts.
Copyright © 2019 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.