CS 415, Section 002 | Sonoma State University | Spring, 2022 |
Algorithm Analysis
|
||
Instructor: Henry M. Walker
Lecturer, Sonoma State University |
This problem asks you compare the performance of six sorting algorithms, including:
In developing the comparison, you will need to code each algorithm in C or C++; and you will need to run all algorithms on the same data sets of varying sizes. Here are some details.
Try to code each algorithm in a similar style, in order to minimize the impact of idiosyncrasies of coding.
Your tests should generate three data sets for files of size 10,000, 20,000, 40,000, 80,000, and 160,000 . One data set should be ordered in ascending order, one data set should contain random data, and one data set should be in descending order.
Each data set is to contain only positive integers, and each data set is to be sorted in ascending order by each algorithm.
Your program should determine the time spent by the sorting algorithm separately for each data set. The timing should NOT include any set up before the sorting algorithm (e.g., not array initialization), and the timing should NOT include any clean up at the end (e.g., memory deallocation, printing). However, the timing should include any required initialization of variables required for the algorithm.
Since processor speeds, machine capabilities, and run-time environments will vary by language, the program should continue testing algorithms with data sets that progressively double in size until some algorithm requires over 15 seconds to finish on one data set.
The program should produce a table of times in the following format:
Data Set Times Algorithm Size Ascending Order Random Order Descending Order Selection sort 10000 Insertion sort 10000 Merge sort 10000 Heap sort 10000 Quicksort 10000 Imp. Quicksort 10000 Selection sort 20000 Insertion sort 20000 Merge sort 20000 Heap sort 20000 Quicksort 20000 Imp. Quicksort 20000 ...
Program sort-comparisons.c provides one possible shell for this program. This abbreviated program includes:
Before expanding program sort-comparisons.c, be sure to consider why the code uses arrays for the data sets (asc, ran, and des), as well as temporary copies of these arrays!
Altlhough collaboration is allowed on this programming exercise, all outside sources and collaborators MUST be cited. Further, over 40% of the code and write-up submitted must be your own. You can talk to others, but you need to do a substantial part of the coding and write-up. Toward that end, the following must be included at the start of your program.
/********************************************************************** * Name: * * Assignment name: Comparison of Sorts * * Assignment for <due date> * ***********************************************************************/ /********************************************************************** * Academic honesty certification: * * Written/online sources used: * * Program sort-comparisons.c by henry m Walker from CS 415 Lab * * [include textbook(s), CS 415 labs or readings; * * complete citations for Web or other written sources] * * Help obtained * * [indicate names of instructor, class mentors * * or evening tutors, consulted according to class policy; * * write "none" if none of these sources used] * * My signature below confirms that the above list of sources * * is complete AND that I have not talked to anyone else * * (e.g., CSC 415 students) about the solution to this problem * * * * Signature: * ***********************************************************************/
Once you have the times collected for the various algorithms, plot the times versus the data set size using any graphing software you wish. (A spreadsheet might be used, but you also might use MatLab, Maple, or other package.) For each algorithm, the times for the three data sets should be connected (that is, one line would connect the times for the insertion sort with ascending data against sizes 10000, 20000, 40000, ... .)
If the graphing software allows, it would be helpful to have the graphs for all algorithms with ascending order combined on one plot, the graphs for all algorithms with random data on a second plot, and the graphs for all algorithms with descending data on a third plot. In addition, a graph of a line (f(n)=n) and a quadratic (f(n) = n2) would be helpful (but not required).
Notes: Much code is available from textbooks and online sources for many of these algorithms.