Selection sort. Be able to selection sort an array. How many compares does it use? How many exchanges?
Insertion sort. Be able to insertion sort an array. How many compares does it use in the best and worst case? How many exchanges in the best and worst case?
Inversions. The number of pairs of elements in a sequence that are out of order. An array with no inversions is ordered.
Partially ordered arrays. Why is insertion sort linear for partially sorted arrays?
Shuffling. Can use sorting to shuffle in n log n time by assigning each value an arbitrary unique value between 0 and 1. Can shuffle in linear time using Knuth shuffle.
public class Card implements Comparable{ // Comparators by suit and by denomination public static final Comparator SUIT_ORDER = new SuitOrder(); public static final Comparator DENOM_ORDER = new DenomOrder(); // Suit of the card (CLUBS = 1, DIAMONDS = 2, HEARTS = 3, SPADES = 4) private final int suit; // Denomination of the card private final int denom; public Card(int suit, int denom) { if (suit < 1 || suit > 4) throw new IllegalArgumentException("Invalid suit"); if (denom < 1 || denom > 13) throw new IllegalArgumentException("Invalid denomination"); this.suit = suit; this.denom = denom; } // COMPLETE THE FOLLOWING FUNCTION public int compareTo(Card that) { } // Compare cards according to the suit only private static class SuitOrder implements Comparator { // Implementation not shown } // Compare cards according to the denomination only private static class DenomOrder implements Comparator { // Implementation not shown } }