Goals for this assignment are to:
Read Chapter 9.
These will not be collected but may appear on an exam. We will go over most of them in class. If you have questions about any of them, please ask!
Use induction to prove that:
Recall, to prove this you must 1) state what you are proving, 2) show that the base case is true, 3) state the induction hypothesis, and 4) prove the induction hypothesis is true.
Programming Problems:
Begin with the same sorting animation program you used in lab 7.
Mergesort: Add Mergesort to your animation. Note that Mergesort does not sort "in place". As a result, the animation won't work because it relies on the list of numbers being in a single array. However, you can still use the animation program to view the array before and after sorting. Do the following:
StoogeSort: Add StoogeSort to the animation program. The algorithm is given by the psuedocode:
StoogeSort(A,i,j)
1 if A[i] > A[j] then exhange A[i] and A[j]
2 if i+1 >= j then return
3 k = floor( (j-i+1)/3 ) // Round down
4 STOOGE-SORT(A,i,j-k) // First two-thirds
5 STOOGE-SORT(A,i+k,j) // Last two-thirds
6 STOOGE-SORT(A,i,j-k) // First two-thirds again.
Be sure to count the number of comparisons and swaps. Calculating the number of comparisons is a little tricky. Note, the number of comparison for n=10 should be 364. To speed things up when testing your program, you might want temporarily to set the delay to zero, or just comment out the pause method. Note, the complexity of StoogeSort is Θ(n2.71).
You must first complete parts 1-3 before getting credit for this.
As mentioned above, Mergesort does not sort in-place, rather it requires extra memory (what is the space complexity?). However, it can be modified so that it uses much less memory. This modification is described in Problem 9.23 on page 251 of your text. Implement this version of Mergesort in your animation program (call the class MergeSortSpace, or something that easily identifies it - don't over write the original MergeSort). What is the space complexity of this new implementation? Does it change the time complexity?
By Monday, Nov 5, zip together the SortAnimation and Minesweeper projects, including the jar files, and email the code as an attachment to gorr@willamette.edu. Place CS241 Lab 8 in the subject line. Please indicate in your email if you have done the extra credit.
By Thursday, Nov 8 demonstrate the SortAnimation and Minesweeper program to the instructor.