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 zero inversions is sorted.
Partially ordered arrays. Why does insertion sort take linear time for partially sorted arrays?
The Card
class is implemented in Java as follows.
Complete the compareTo()
method.
public class Card implements Comparable{ private final int suit; // suit (CLUBS = 1, DIAMONDS = 2, HEARTS = 3, SPADES = 4) private final int rank; // rank (DUECE = 2, JACK = 11, QUEEN = 12, KING = 13, ACE = 14) public Card(int suit, int rank) { if (suit < 1 || suit > 4) throw new IllegalArgumentException("Invalid suit"); if (rank < 2 || rank > 14) throw new IllegalArgumentException("Invalid rank"); this.suit = suit; this.rank = rank; } // COMPLETE THE FOLLOWING METHOD public int compareTo(Card that) { } }