CS 2223 May 01 2018
Lecture Path: 28
Back
1 Final Today
1.1 Why does an audio CD contain 74 minutes of music
Sufficient evidence points to the desire (by record company executives as well as designers) to fit the complete Beethoven 9th symphony on a single CD disk.
1.2 Word Ladders
Note that in the english.words.txt file there are 5,875 four-letter words. From this set, there are a total of (5875*5874)/2 = 1,725,4875 possible pairs from which to form word ladders.
An exhaustive search requiring 3.5 hours shows that only 60 words (1.02%) of the four letter words are not involved in a word ladder. This list includes:
adze akov ankh awfu awol ceyx degu ebbs ecru efik ejoo ekoi elhi enif enki envy epee epha eruc esox etym evil expo hexa hoju hymn iglu ijma imam isba itys ivin jeux jism juju llyn lwei ngai niog ocht odso ogpu ohms olpe omao opsy pfft pfui sybo tsia ubii ughs ulmo upby upon vlei vuln wrox ycie zyga
The word which tied for most number of word ladders is "aals" with 5,805 possible word ladders deriving from it alone.
1.3 Fewest number of comparisons to find largest and smallest
This problem, posed in class yesterday, is evidence of a problem in which the naive algorithm has best/worst cases of the same number of comparisons.
In lecture, I posited it would be 2*(N-1) in the worst case; it turns out with a simple change, you can do one better, which would be 2*N-3. See the uploaded code for day27.
In the best case, the array is already sorted, and if you constantly check for the maximum first, you will avoid comparisons on the min.
for (int i = 1; i < n; i++) { // if smaller than min, reset if (compareTo(ar, i, max) > 0) { max = i; } else if (compareTo(ar, min, i) > 0) { min = i; } }
The above code has lower-bound on the number of compares at N-1, while the upper bound would remain 2*(N-1). See the code repository for the change that would eliminate one comparison, to bring us down to 2*N-3.
1.4 Exam Today!
Find an empty seat and try to make space between you and a neighbor.
1.5 Version : 2018/04/22
(c) 2018, George Heineman