Homework 5 (Optional) , Improving sorts.

Short Description:

Investigate how different improvements can impact sorting time.

Goals

When you finish this homework, you should have:

Note:

This assignment is optional. If you do this, I will use the score for up to 25% of your final exam. Your final score may not exceed 100%.

You do not need to do all three parts, each part is worth 8 1/3% of the test.

Exceptionally well done reports may result in additional credit.

Formal Description

Continue your investigation into algorithm performance by implementing and testing two improvements and one compiler option.

Insertion sort algorithm. As stated in class, swapping the element to the right place in the array is less efficient than moving the array up and only inserting the element once a space has been opened. How important is this? Implement the improved algorithm and test the performance of this implementation against the original algorithm.

Cocktail Shaker Sort. This sort is an extension of the bubble sort. One version of this algorithm:

It seems that this should be faster than the original. Implement and test this theory. Report your results and state any conclusions.

Compiler optimization. The gcc compiler supports multiple levels of optimization. By default there is no optimization, but the following flags provide high level optimization
Flag Effect
-O1 Basic Optimization, the compiler does what it can quickly
-O2 Moderate Optimization, increased compile time leads to better code performance
-O3 Aggressive Optimization, a potential for greatly increased compile time but a chance for much better code performance
Select any one of your O(n2) algorithms and conduct experiments on the impact of compiler optimization. Report your results and conclusions. You need only do this with one sort, not all four/five.

You can change the compiler optimization by adding that value to the CXXFLAGS line in the Makefile, or if you compile by hand, adding the flag to the compiler command.

Write a report describing your findings and interpreting the results. Your report should follow the IMRD format

Please note, your discussion must include at least one graph, table and a discussion comparing these sorts to the sorts in the last assignment.

Please include a graph providing a timing performance for all of the sorts consider (bubble, bad insertion, improved insertion, cocktail shaker and compiler optimization). If you only perform part of this assignment, you are not responsible for the graphs for the parts you do not do.

Notes

Please optimize your code only for the last part of this experiment.

You may use components of the standard library, my framework relies on these heavily. You must, however, implement the sorting algorithms yourself.

I encourage you to use the chronos library for time and the random library for random number generation. You may use my framework and are excused from deep knowledge of these libraries.

  • If you wish, my Makefile is here.

    Required Files

    A zip or tar file containing

    Submission

    Submit the assignment to the D2L folder Homework 5 by the due date.