Objective:

To learn about and analyze various sorting algorithms.

Description:

For this project you are going to write several new functions called: SelectionSort, InsertionSort, MergeSort, and QuickSort. Each function should take an array of integers (and any other parameters you choose) and each function should sort the array using the appropriate sorting algorithm. Once you have the functions written and working correctly, run some tests to determine how long it takes the algorithms to sort arrays of various sizes. Start with arrays of 20000 elements. Continue to double this amount until you reach 640,000 elements. Call the clock() function before and after each sort to determine the total amount of elapsed time required for each sort (this will give you time in milliseconds).

You can save yourself some time and trouble by writing a procedure to create dynamic arrays of various sizes filled with random values. You can also statically declare an array with all of the sizes that you need already declared (from 20000 to 640000). Try to come up with several functions to make your life easier here, like both a runAllTests and a runTest where you pass it in the size. I'd like you to run the test at least 3 times with each array size and take the average of those times.

MAKE SURE YOU DELETE ARRAYS ONCE THEY ARE NOT NEEDED! Why would you need to do this?

You should save test results to text files for easy reference. The files don't have to be complex, each line should just say something like:

Insertion Sort: 20000 elements across 3 consecutive tests took on average 2263 milliseconds

While the library class stopwatch I gave you is in seconds, I'd like for it to be expressed as milliseconds and with no remainder. When you are finished with the tests, prepare a short single document report that describes your results. The document should contain a line graph prepared with Microsoft Excel showing the times required for each sort with each algorithm. For easy comparison, also put all results into one graph. Write a few paragraphs explaining what you think the results mean. Did sorts take as long as you thought they would? Add as an appendix a copy of all your test files.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.