Assignment 6
Comparing and Simple Sorting
Submit before 11:30 PM Saturday March 7

Overview

For this assignment you will use simple sorts and comparison interfaces.

Here's the starting code for this assignment.

Analysis Problems

Answer the following questions, providing justification for your analysis. To check your answers, you may want to test them on the sorting code provided with the class.

  1. Consider this array of 5 integers: 4 2 8 3 1. How many (a) comparisons and (b) swaps will be needed for the selection sort? For the insertion sort (questions c and d, respectively)?
  2. Consider this nearly sorted array of 5 integers: 1 3 2 4 5. How many (a) comparisons and (b) swaps will be needed for the selection sort? For the insertion sort (questions c and d, respectively)?

Comparable vs. Comparator

  1. Using the AltString class as a starting point, write the compareTo method so that strings are first sorted by their length (shortest to longest) and then, for strings of equal length, in lexicographic order.
  2. Write a comparator for the string class so that strings are first sorted by their length (shortest to longest) and then, for strings of equal length, in lexicographic order.
  3. Write a main method in a CompareDemo class that demonstrates that your code from the previous two questions works.

Comparable movies

Modify the Movie class so that it lists recommended movies based on Wikipedia articles and your reference movie. Your modification should include an implementation of the compareTo method so that the movie object are properly sorted. Make sure that your list presents the highly recommended movies first. We will discuss this code and needed process in class.

Create a class called Demo whose main method fully runs your code and demonstrates what it does. Its output should include any necessary text for explaining what to do and what is presented.

Note: most of the technical coding has already been done for you. Since your modifications should be minimal, this should be more fun than challenging. Talk to me if you are having difficulties.

For additional (non-required) challenges, do any of the following:

  • Use a stop word list that removes non-diagnostic words (e.g. "and", "the", "if") from the analysis.
  • Use a restricted word list that only considers particularly diagnostic words (e.g. "comedy", "thriller", "violence", "Spielberg").
  • Implement some combination of the above
  • Apply a stemmer that strips words to their root (e.g. search on "porter stemmer").
  • Write code that "caches" results so that internet queries are not performed every time your program runs.
  • Modify the class to work on objects other than Movies.

Submission

Submit a zipped folder that includes the written answers (any common format is fine) and the code in a package named "assn6".