Assignment 6

Due Tuesday, August 2 at 9:00 AM

Be sure you are acquainted with my collaboration policy and my late policy, both found on the main course webpage. If you are working with a partner, be sure to include both of your names.


Introduction

In this assignment, you will implement three sorting algorithms--two you've seen before (InsertionSort and QuickSort) and one new one (BubbleSort). I have written some skeleton code containing method signatures for the three sorts, some helper methods, and a main method. Here is the file:

After implementing the algorithms, you will test their runtimes to see if they are different. (Hint: They are different.)

Bubble Sort

In bubble sort, the idea is to make repeated passes through the array, comparing adjacent elements and "bubbling" the greatest element all the way to the top of the array. Once this has been done once, the greatest element is in its proper position, and the next pass through the array need only make comparisons up to the second to last element. The next pass need only bubble up to the third to last element, and so on.

Here is an example:

Bubble the greatest element:

[3, 2, 5, 1, 4]
[2, 3, 5, 1, 4]
[2, 3, 1, 5, 4]
[2, 3, 1, 4, 5]

Bubble the second greatest element:

[2, 1, 3, 4, 5]

Bubble the third greatest element:

[1, 2, 3, 4, 5]

Bubble the fourth greatest element: *already done

Bubble the fifth greatest element: *already done

Describe the runtime of this algorithm in the comments of your implementation. If you have any questions about it, let me know.


Acquaint Yourself with the Code

Read through SortTest.java and familiarize yourself with what it is doing. It contains the following methods:

Though you will only need to implement a couple of methods, make sure you understand everything that is going on.

Implementing the sorting and sort checking methods

Your job for this assignment is to implement isSorted(), bubbleSort(), insertionSort(), and quickSort(). Remember to explain the run-time of BubbleSort in the comments of its implementation. Most of these we have already done in class--this is not meant to be an extraordinarily difficult assignment. You may want to create private helper methods. For instance, in class, we had helper methods for partitioning the array in a quick sort, and an overloaded auxilary method allowing us to perform recursion. Any such methods are entirely up to you.


Turning in your work

To hand in your program, copy SortTest.java and any other files needed to create SortTest.class to the following directory:

/p/course/cs367-ealexand/handin/login-name/P3

Use your actual CS login name (not your UW NetID!) in place of login-name. Be sure that a comment at the top of the AVLTree.java file gives the name(s) of the author(s) of the code.

If you worked with a partner, then only one of you should turn in the program files as specified above. It doesn't matter which partner hands in the program files.

Do not copy any ".class" files, and do not create any subdirectories in your handin directory. Note that for this assignment, you should test your program thoroughly, but you do not need to hand in your test data.

You will be graded on program correctness, error checking, and general style.