CS 4521 PA1 — Array Algorithms

Due September 15, 10 points.

For this assignment you will download and complete a NetBeans project. This project contains code for an array model and operations that act on the model. Changes made by the operations are displayed in the main program. Some operations are already implemented.

There is a class for a quicksort operation that is complete except for a few lines that implement the partition loop. You should complete this operation as a lab exercise to get a feel for working with the array model.

Then you can complete the assignment outside of lab. This involves completing another operation class. The operation in this class operates on an array of randomly ordered characters. Given two parameter characters ch1 and ch2, it rearranges the characters in the array into three segments:

Setup

  1. First you need to download the file Quicksort.zip to a convenient location.
  2. Then unzip the file. This will create a NetBeans project folder.
  3. Run NetBeans and open this project.

Lab Exercise

This exercise should be completed in lab. The objective is to get a feel for working with the array model in an environment where you get quick answers to your questions.

First, open the file sorts.Partitioner.java in NetBeans. This is the only file that you will need to modify to complete the lab exercise part of the assignment. You can also view this file as a web page here.

You will need to add a few (about 5) lines of code in the partition loop after the FIXME comment (line 79). You should first read and understand the comments about array indices in the earlier parts of the code. Ask questions about anything you don't understand.

The code that you add has a simple objective: make progress towards termination while maintaining the loop invariant. The loop invariant is described here.

Assignment

This part of the assignment is due September 15.

To complete the assignment you will need to implement the code for the operate() method in sorts.Classifier.java. The operation in this class operates on an array of randomly ordered characters. Given two parameter characters ch1 and ch2, it rearranges the characters in the array into three segments:

You should first plan the loop invariant for this code. Draw pictures of how you want the array to look when done and how it looks when you start. Then draw a picture that generalizes both of these pictures. That is your loop invariant. You may want to reread the Quicksort presentation. Start early on planning the loop invariant.

Start early on planning the loop invariant. It won't take long to write the code, but it could take a long time to get it right if you haven't thought about the invariant beforehand.

Submission

You should be prepared to demonstrate your complete assignment in lab on September 15.

Section Header

Section overview text.