Homework 6
Short Description:
Conduct implement and investigate the performance of various sorting algorithms.
This assignment is worth 15 points.
Goals
When you finish this homework, you should:
- Compare different sorting algorithms.
- Implement different sorting algorithms.
- Produce a quality lab report.
Formal Description
Implement the following sorting algorithms:
- Insertion Sort.
- Shell Sort with Hibbard's gap sequence.
- Bubble Sort.
- Quicksort.
- Mergesort.
- Radix/Bin sort.
For each sort, you should compute the following statistics:
- The number of comparisons each sort performs
- The number of swaps each sort performs
- The wall-clock time for each sort
You should count the comparisons in the following manner.
// declare a global variable comparisons
int comparisons
...
bool compare(element a, element b) {
comparisons ++;
return a < b
}
...
void mySort() {
for i = start; i < stop; i++
for j = i+1; j <= stop; j++
if compare(array[i] , array[j])
swap(array[i],array[j])
return
}
...
// main routine
comparisons = 0;
mySort()
ThisSortComparisons = comparisons;
To count moves, you should do the same thing for swap, but you will
probably need to do something for a copy operation as well as a swap operation.
Count a swap as two data movements, and a copy as one.
You should test the routines for values of two between 29 and 214.
You may sort any data you wish.
Your main should work as follows:
for i <- 9 to 14 do
// generate a new array of a given size
size <- 2^i
generateMasterArray(master, size)
for each sort {
copyMaster(master, copy, sort);
initializeStats();
sort(copy,size)
finalizeStats()
if (!IsSorted(copy, size)) {
cout << " sortname Failed " << endl;
}
printStats()
}
When you are finished produce a report summarizing your results. This report
should be produced using a word processor, and contain the following sections:
- Introduction: briefly introduce your experiment.
- Algorithms: List the important algorithms in both English (with a high level description of the algorithm) and in pseudo code.
- Methods: Explain what you did and how you did it. Describe the computing environment, input, output and other conditions which might effect the experiment.
- Data: Give tables summarizing your results. Make sure that your tables are labeled. Reference your tables in the text.
- Analysis: Describe what you discovered. Include graphs to help interpret the data. Make sure that any graphs are labeled. Reference any
graphs or tables in your text.
- Verification: Describe how you verified that your algorithms,
code, and methods are valid.
- Conclusions: Summaries your results. Make recommendations on
which algorithms to employ and under what conditions they
should be employed.
- Further Investigation: Describe further experiments or investigations your work might suggest to you.
- References: Cite references to any material used.
- Appendices: Items which you feel are required to make your report complete. For example, if you wish to include code, or code fragments, this is the place to do it.
Input
None
Output
Algorithm Statistics
Discussion
You should have an analysis of each sort for each statistic collected.
Furthermore, you should produce graphs of the data. Finally you should
discuss the results and suggest where each sort could be used.
Required Files
The source code, Makefile, and your report.
Extra Credit
none
Submission
This assignment is due Dec 7 at class time. You should email a tar file
of your homework directory to dbennett@edinboro.edu. Furthermore you should
submit, before class begins, a hardcopy of your lab report.