When we are dealing with data, we often want to put it in ‘order’. To do this we can sort it. In this assignment you will implement three simple sorts and analyze the sorting algorithms and your code.
In this assignment we have some specific requirements for your code. We have to satisfy the requirements of the problem in order to have correct solutions. This will give you early practice of writing code that meets some simple requirements.
The second part of this assignment is to continue exploring handling binary data in Java. You will write a class that reads in a file with a specific format.
This is where we will put all our classes for homework 03.
You’ll need the SortRecord class. It is a generic that can keep track of the number of comparisons and swaps for each item in the array.
Each method should implement the named simple sort algorithm on the array data. Use the Comparator<E> to determine the order of the items in the array. Sort the arrays in ascending order. The ‘smallest’ element should be in position 0, ‘largest’ in data.length - 1.
The methods should keep track of the number of comparisons, the number of swaps for each item, and the amount of time it took to sort the array. To record the time taken, your code should call System.nanoTime at the beginning of each of the methods and save the value as the start time. It should then call System.nanoTime again at the end, and print the difference between the two times. The difference may be zero if your system clock does not update the time quickly enough, but otherwise should accurately report how many nanoseconds (billionths of a second) it took to execute your code. When the sort methods complete they should report the number of comparison, swaps, and the execution time in nanoseconds.
Ensure that your implementation has the following characteristics:
The BigO for insertion and bubble sort on sorted data must be BigO(n);
The number of swaps for all three sorts on sorted data must be 0.
Create an AltitudeComparator that implements Comparator<Cloud> deciding based upon the Clouds’ altitude values.
Create a ShapeComparator that implements Comparator<Cloud> deciding based upon the shape of the Clouds.
If you created them last week you are done. If not create them in package edu.ics211.h02.
We are going to use the CloudSorterTest.java JUnit tests to evaluate your homework for correctness.
You may add any more tests if you want to.
Write up a runtime analysis of each of the sorting methods, giving the big-O of each, and explaining how you got your results. Your analysis should refer to your code by line number. Send your analysis to the TA together with your code. This part counts for 25% of the grade on this assignment. Even if your code doesn’t work, you should do this part to the best of your ability.
Completing this part will help you with Homework 11: Huffman Trees.
We are going to continue exploring handling binary data in Java. You will write a class that reads in a file with a specific format.
The file has the following format:
The IReadFile interface has one method in it.
What are the steps you need to read in the contents of the file?
Java has a nice class DataInputStream that allows you to read in different types. I recommend you use this class. Also the String class has a nice constructor that takes an array of bytes and a Charset.
You can test your implementation using ReadFileTest. We will be using this JUnit test to grade this part of the assignment. ReadFileTest test against four files.
Download the files an place them in your project at the save level as your src directory. As shown below.
Criterion | Excellent (100%) | Satisfactory (75%) | Borderline (50%) | Unsatisfactory (25%) | Poor (0) |
---|---|---|---|---|---|
Adherence to standards - 2 points Does it conform to standards in every detail? |
No errors. | Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. | Misses the point of the assignment. |
Breakdown (modular design) - 0.5 points Does it demonstrate good modular design? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Correctness of code - 2 points Does it work? Does it pass JUnit? |
Passes all tests. | Works for typical input, may fail for minor special cases. | Fails for typical input, for a minor reason. | Fails for typical input, for a major reason. | No. |
Documentation, and style - 2 points Is it clear and maintainable? Does it pass CheckStyle? Are your steps documented? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Efficiency of code - 1 point Does it use the Java features well? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Algorithm Analysis - 2.5 points |
The assignment is due on Friday at 11:55pm. You may turn it in early.