Today we concluded our unit on sorting algorithms in Computing Science 12. I was very impressed by the work the class did to prepare. Students were responsible to research 2 O(n^2) and 2 O(nlgn) sorting algorithms and 1 wildcard that could be anything they like. The wildcard sort would be with integers so students could learn about sorting algorithms that are not comparison based (Radix, Bucket, Counting, etc.), if they wanted to (not a requirement). You can read more about it here.

Students have to implement an interface (download it here) to “plug” into the competition. I built a skeleton project that looks a little cheesy but you can see visually who’s winning as each round completes. I’m not promising it’s perfect, but it added the dramatic effect that had everyone staying in a lunch to watch the results.

Get your copy here (a Greenfoot project).

You’ll probably do your own tinkering but here’s a few hints about how to setup the competition:

There are two variables to control the size of the test data generated. Depending on the speed of your computer and number of competitors you will probably want to adjust these.

- public static final int SIZEN2 = 1000;
- public static final int SIZENLGN = 100000;

To add your students to the competition they must load their classes into the project and add a new Object from their class to the loadCompetitors() method.

When you compile the project it will start running immediately. Click on the button at the bottom to determine which algorithm will run during the competition. Then hit the usual Greenfoot “play” button and watch the competition unfold. Once the competition is finished just click the button to indicate what the next one will be and you’re ready to go again.

Points are by placement. In a race with 10 competitors, 1st place gets 10 points, 2nd gets 9, 3rd gets 8, … In the event of a time, everyone in the tie gets the lowest amount of that group. For example if three people finished 2nd the points would be 10 for 1st, 7 for 2nd, 7 for 3rd, 7 for 4th, and 6 for fifth, … The competition checks to see if data is sorted properly (it can be either ascending or descending). When a student’s algorithm did not sort the data they are assigned a time of Integer.MAX_VALUE to place them in last.