CS 241 Data Structures- Lab 6, Due 2/28 (or, if you promise to study the review sheet before then, 3/5

Algorithm Timing Analysis

Your task for this lab is to implement two new sorts and one old sort to verify empirically whether they are θ(n^2), θ(n), and θ(nlogn) (as advertized).


  1. If you would like to work with a partner, you may. If you'd like assistance in finding a partner, let me know.
  2. Choose three sorts
    1. Implement either merge or quick sort
    2. Implement either radix or table (counting) sort
    3. Select one of insertion, bubble, and selection sort
    4. Test them to make sure the actually sort! Leave a way to simply run the test code during your demo (diagnostic mode is a nice feature in any non-trivial program!).
  3. Write a TimingGenerator class which is passed an AbstractSort and returns a TimeList, which is a pseudonym for an ArrayList<TimeData> (define a TimeData class which includes n and t (where n is the length of the list and t is the time to sort it) -- include accessors for both variables). I.e. the TimeGenerator should time the sort with n=1000*2^x, where x=0,1,2,...,10 (or as far as makes sense; i.e. if it takes 30 seconds to do x=6, don't bother to do x=7, and if n>1000000, stop!), and add a TimeData to the list for each.
  4. Write an Analyzer class which is passed a TimeList and a String telling which sort it is associated with. The Analyzer should classify the running times as θ(n), θ(nlogn), θ(n^2), or something else and return its classification as a String. Append that String to a TextArea along with the the TimeList and the name of the sort, so the user can tell what's happening. You will need to think about how to design your Analyzer to deal with the fact that θ is an approximation as n->∞!

    Remember that the times for short runs are noisy and may be ignored; perhaps compare the times for the largest n and n/2 to decide what T(A(n)) is?

  5. Your code should automagically run and analyze the three sorts you have chosen.

How to get credit

Demo your code during lab and email me the source code for Analyzer and your two new sorts, as text (i.e. copy/paste the code into the body of the message -- no zips, no include file).