October's homeworks:
• Homework 5 (6-1 and 6-2(a--c)), due 26 October.
• Homework 4 (6.2-6, 6.4-3 and 6.4-4), due 19 October.
• Homework 3, due 7 October.

28th. In Wednesday's class, we showed that Quicksort is very slow (time Θ(n2)) on an array which is already sorted; but that, if each call to Partition divides its argument into two approximately equal halves, then Quicksort is as fast as the best sorting algorithms we have. We introduced the idea of randomly choosing the pivot in Partition in order to help avoid worst-case behaviour. Homework for Wednesday was 7.4-2 and 7-1(b--d).

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.

25th. In Monday's class, we discussed the Quicksort algorithm, which makes essential use of the Partition algorithm. Quicksort actually has a slower worst-case running time than the fastest sorting algorithms we know, but it is nonetheless preferred for many practical applications.

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.

14th. Please note that Homework 4 is due Wednesday, 19 October, not 26 October.
13th. In class on Wednesday, we formalised the idea of using the algorithms Build-Max-Heap and Max-Heapify to implement a sorting algorithm Heapsort. We also wrote the Max-Heapify routine. Homework for Wednesday was 6.2-6, 6.4-3 and 6.4-4. (Sorry, no handout is available this week.)

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 .

10th. In class today, we showed how to maximise the (approximation to the) probability of hiring the best candidate using On-Line-Hiring.

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.

9th. In class on Friday, we computed the number of people required in a group for us to expect at least one pair of people in the group to have the same birthday. (This is slightly bigger than the number of people required merely to have an at-least-even chance of a common birthday). We also discussed the algorithm On-Line-Hiring and computed its exact probability, as well as a more manageable approximation.

The complete solution set to Homework 2 is now available.

5th. Today, we showed that Permute-in-Place does indeed produce a uniform random permutation of its input. We also computed the number of people required in a group for there to be an at-least-even chance that two people in the group share a birthday.

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.

4th. In Monday's class, we computed the running time of Permute-by-Sorting and proved that the algorithm works with high probability. We also developed an algorithm, Permute-in-Place, which is guaranteed to work, runs faster and uses less memory (in fact, as suggested by the name, it works `in place', i.e., using only O(1) memory). The (partial) solution set to Homework 2 is now available.

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.

3rd. In Wednesday's class (28 September), we proved the last case of the master theorem (in which the `overhead function' satisfies a f(n/b) ≤ γf(n) for some γ < 1) and began to discuss the idea of a uniform random permutation. Students should read Appendix C, Sections 1--3, to make sure that they are comfortable with the ideas of probability we will be using.

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.