Today, we showed that sorting an already-sorted array is actually the worst case for Quicksort. (Showing that the fast behaviour described above is the best case is part of the homework.) Following exercise 7-2, we began to describe a computation for the average running time of Quicksort, which we will see is actually asymptotically the same as its best running time.
Homework for Monday was 7.1-2, 7.2-2 and 7.2-3. For 7.1-2, it may be helpful to try to write an algorithm dividing the array to be partitioned into five regions, rather than the usual four.
The five routines, Heap-Extract-Max, Heap-Increase-Key, Max-Heap-Insert, Heap-Maximum and Heap-Insert, listed in class on Monday included one too many. Delete Heap-Insert from the list (it is redundant when you already have Max-Heap-Insert). Also, see Section 6.5 instead of Section 6.4 for these routines.
Class does not meet next Monday. I will be gone all next week, but will attempt to respond to any e-mail questions as soon as possible. The substitute has also agreed to accept e-mail questions at .
We have now completed our discussion of Chapter 5. Next we will discuss variants on and improvements of the sorting algorithms we know already. Today we defined the idea of a heap and a max-heap, and outlined how these concepts can be used to sort an array. The formal algorithm will be discussed on Wednesday.
The complete solution set to Homework 2 is now available.
The homework 3 handout had a typo. The second binomial coefficient in the statement of CRLS C.1-11 should be n - j choose k, not n choose k. This typo has been corrected. You may hand in a solution to either problem.
A complete solution set for Homework 2 will be available later today or tomorrow.
Please note that, if you have already received credit for any part of problems CRLS 4-5 or 4-6, you need not rewrite your solutions. However, you should hand in any work for which you have already received credit, so that the credit is recorded correctly. If you received partial credit for a part of a problem, you may (but need not) rewrite it to earn full credit.
In Friday's class (30 September), we described the algorithm Permute-by-Sorting for uniformly randomly permuting an array. This algorithm has some weaknesses, but performs its job correctly with high probability. We will discuss an algorithm today which avoids these weaknesses, and is guaranteed to perform its job correctly.
On Friday, we also discussed CRLS 4-5 (on Fibonacci numbers) from Homework 2. A small typo in the Homework 2 handout (which had F0 = 1 instead of F0 = 0 in CRLS 4-5) has been corrected. CRLS 4-5 and 4-6 are both reassigned, to be collected this Wednesday (5 October). The due date for Homework 3 has been moved to 7 October.
A solution set for the remainder of Homework 2 will be posted later today.