Computer Science 501
Data Structures and Algorithm Analysis
Fall 2014, The College of Saint Rose
This week's lab focuses on sorting. You will take the next step toward our upcoming empirical analysis of sorting algorithms in a practice program, then get an introduction (or reintroduction) the power of Java's Comparator interface as it applies to writing a generalized sorting method. You will extend the functionality of an existing class using inheritance, you will implement a simple sorting procedure within this extension, and you will learn about Comparators, which provide a more flexible mechanism for ordering objects than the Comparables we have seen in class.
You may work alone or in a group of two or three on this lab. Of course, collaboration with your partner is unrestricted. You may discuss the lab with your classmates and give and receive some help, but your submission must be your own work (or that of you and your teammates, if you choose to form a group).
Getting Set Up
To get your BlueJ environment set up for this week's lab assignment, start BlueJ and choose "New Project" from the "Project" menu. Navigate to your folder for this course and choose the name "Lab6" (no spaces) for the project.
Create a document where you will record your answers to the lecture assignment and lab questions. If you use plain text, call it "lab6.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab6.pdf" before you submit it.
Lecture Assignment Questions
We will usually discuss these questions at the start of class on the lab due date, so no credit can be earned for late submissions of lecture assignment questions.
Practice Programs
For this week's practice program(s), you will be taking another step toward an empirical analysis study of sorting algorithms.
Your program should be able to gather timings for sorting algorithms operating on arrays of int. It should have options to set the array size, the number of trials (to improve timing accuracy), the ability to generate initial data that is sorted, nearly sorted, completely random, and reverse sorted. Design your program to make it easy to implement a variety of sorting algorithms. Include the ability to count basic operations (number of comparisons and/or number of swaps) as well as to generate timings. You will need the ability to generate and report tabular data to show how your sorting algorithms perform on different sizes and distributions of data.
For this week, you should implement just three "naive" sorting algorithms in your program(s):
Tips, Tricks, Precautions, and Suggestions
10000 bubble random .034693
might indicate for an input size of 10,000, using a bubble sort on random input took .034693 seconds.
Programming Assignment
We will do the laboratory at the end of Chapter 6 in Bailey.
Please note the following clarifications, modifications, and explanations relating to the lab procedure outlined in the text:
public class MyVector<T> extends structure5.Vector<T>
Keep in mind that as an extension of structure5.Vector, methods of MyVector will have access to instance variables and methods declared as protected in the structure5.Vector implementation. Make good use of this fact!
Important Note: The elementData array in structure5.Vector is declared as private rather than protected for type safety reasons. This means, unfortunately, that MyVector will not be able to access the array directly. Fortunately, Vector has mutator and accessor methods that are (almost) as good as direct access to the array.
Another Important Note: You do not need to copy or rewrite Vector.java! When you extend the existing Vector code, it will inherit all of the constructors and methods. You're just adding one method.
You may choose from the data files I have provided in the "labs/comparators" directory in the class shared area. See the README file there for more information. You may also use some other data that you find interesting.
Submitting
Before 6:00 PM, Tuesday, October 14, 2014, submit your lab for grading. There are two things you need to do to complete the submission: (i) Copy your file with the answers to the lecture assignment and lab questions into your project directory. Be sure to use the correct file name. If you prepared your answers in Word, export to a PDF file and submit that. (ii) Upload a copy of your lab (a .7z or .zip file containing your project directory) using Submission Box under assignment "Lab6".
Grading
This assignment is worth 60 points, which are distributed as follows:
> Feature | Value | Score |
LA Question 1 (6.13) | 2 | |
LA Question 2 (6.18) | 4 | |
General sorting algorithm test framework | 5 | |
Java code for specific sorting algorithms | 12 | |
MyVector correctness | 12 | |
Comparators correctness | 5 | |
MyVector and Comparators design and style | 5 | |
MyVector and Comparators documentation | 6 | |
Sorting applications | 3 | |
Question 1: Thought Question 1 | 3 | |
Question 2: Thought Question 2 | 3 | |
Total | 60 | |