Project 1: Sorting

The goal of this project is reinforce the work on sorting we have done in lab and in class, and to give you more practice working with linked lists.

1. Introduction and setup

In this project, you will implement the bubble sorts listed in lab 1 that we did not have time to get to. First, make a new directory for this course (if you were not the partner logged in during lab 1) and a directory for this project.

mkdir cs235
cd cs235
mkdir proj1
cd proj1

Also, copy the framework files that you used in lab. I have made a small modification to SortArray.java and SortList.java: they now print the array/list only if it is of size 20 or smaller. This way you can debug your programs with small arrays and then run experiments on larger ones without having to see all the array as output. For this reason, I recommend you copy a fresh version of the files and do not use the versions you used in lab. Also copy the file DumbBubbleArray.java.

cp /homeemp/tvandrun/pub/245/SortArray.java .
cp /homeemp/tvandrun/pub/245/SortList.java .
cp /homeemp/tvandrun/pub/245/IntListPair.java .
cp /homeemp/tvandrun/pub/245/Node.java .
cp /homeemp/tvandrun/pub/245/DumbBubbleArray.java .

2. Implementing bubble sort

Do the implementations of bubble sort described in sections 5 and 6 of lab 1. The first one of these (the naive version of bubble sort on arrays) is already done for you (DumbBubbleArray.java); this is the same code as you'll find on your handout from Friday, except with the counting mechanism added. Your task is to complete the other three implementations.

Document your code using the same format as we used in CS 235; for those of you who didn't take CS 245, for this project this means

Use the documentation of the file DumbBubbleArray.java as an example, and see the course style principles for more information. I will be reviewing the details of other style concerns as they become relevant.

3. Experiments

Use the four bubble sorts to see how they perform on arrays of size 10, 100, 1000, and 10000. Run the programs for 10 arrays at each size, and make a table to report the best, worst, and average number of comparisons for each size and sort version.

4. To turn in

Turn in a hard copy of your code and your table. You do not need to write a verbal report.

The command to print files nicely in 2-up form is

a2ps -P sp filename

DUE: Thursday, Jan 18, 5:00 pm.


Thomas VanDrunen
Last modified: Mon Jul 23 15:32:40 CDT 2007