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:

Formal Description

Implement the following sorting algorithms:

For each sort, you should compute the following statistics:

  1. The number of comparisons each sort performs
  2. The number of swaps each sort performs
  3. 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:

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.