Homework 7
CS2110 Programming for Informatics
Due Wednesday, April 7 by 10:00pm
6 points

1. Carefully compare several sorting methods and produce a document discussing your results. You will be graded on the quality of your test data, the effectiveness of your charts/graphs, and your written discussion of the results.

Start with the code in hw7sorts.py. The file includes four sorting methods: selection, insertion, merge, and builtin (Python's built-in sort), plus some commented-out pylab code that can serve as a model for your graphing/charting code.

For this problem, you must add two additional sorting functions to the file and compare the running times of all of the sorting functions on a variety of data. Make sure you use large enough and varied enough data!

One of the sorting functions you must add is quicksort. The other can be any other method you find (except bubble sort). You may search the Internet (or books) for Python implementations to use. Be careful with quicksorts found on the web! It's easy to find "bad" ones - use knowledge of quicksort from lecture 30 to find a good one.

You should compare all of the sorts on at least three kinds of data - randomly ordered, already sorted, and reverse sorted. You should test on a wide range of list sizes, including very large lists that will adequately demonstrate the differences in performance between the sorting methods. Note that you'll likely need several different charts. In particular, for instance, you won't be able to run O(n^2) sorts on large enough lists to see useful differences between the faster sorts. So, make a chart that plots all six sorts up to some size that's reasonable for the slow sorts. But then, drop the slow sorts and make a another chart with only the faster sorts, using MUCH larger maximum list sizes so you can see the differences between the faster methods. The write-up will likely be a few pages, including both your charts and text discussing your comparisons and conclusions about the relative performance of the various sorts. Where appropriate, include assessment of best/average/worst base behavior, and of how performance data fits with what we know about the Big-O running time bounds of these methods.


For this assignment, submit two things:
  1. one Python file containing everything in the original hw7sorts.py plus what you added - the code you used to generate your test data, timing results, and graphs/charts, and the additional sorting methods.
  2. a pdf document containing your write-up. NOTE: .doc,.rtf, and similar documents are not acceptable! Convert to pdf before submitting (via "Save As" or similar means)