Background: Ch. 10, 7.
Due October 2nd:
- 4.1: Given a list L of n numbers, we want to compute
. Prove that setting x equal to the median of L
minimizes the expression. [Extra Credit!] - 4.2: Given a list L of n numbers, we want to compute
. Prove that setting x equal to the mean of L
minimizes the expression. [Extra Credit!] - 4.3: Give an algorithm for efficiently computing the mode of a
list of numbers (not necessarily sorted).
- 4.4: Give an algorithm for efficiently computing the rank of GPA
x both when the list L of GPAs is sorted and when it is not.
Give tight worst-case running-time bounds.
- 4.5: Show that the expected running time of SELECT is
O(n). Hint: Modify the quicksort recurrence.
- 4.6: CLR Exercise 10.3-3 (pg. 192).
- 4.7: CLR Exercise 10.3-7 (pg. 192).
- 4.8: Say we have two heaps, A and B, each of size n, and we
want to create a third heap C. Here are two ways to do that.
Method 1 runs through the elements of A and INSERTs each one
into B. Method 2 simply copies all the elements of A and B into
a new array C and calls ``build-heap'' on the result. Give
asymptotic upper bounds on the running time of these two choices.
Which do you prefer? (Note that there are alternate implementations
of heaps that support this ``merge heap'' operation in
time!) - 4.9: We've got a set of n distinct positive integers, e.g., (7,
10, 9, 19, 8, 6). There are
subsets. Here's one: (7, 10,
19, 8). We define the sum of
a subset to be the sum of the integers in that subset (59 and 44 for
the two subsets here). Give an efficient algorithm to list the n
subsets with the largest sums. Hint: use a priority queue to store
the subsets that might have the largest sums. Give a bound on the
running time of your algorithm. - 4.10: CLR Exercise 7.5-2 (pg. 150).
- 4.11: CLR Exercise 7.5-5 (pg. 151).
- 4.12: CLR Exercise 13.2-1 (pg. 249).
Up: HOMEWORK
Previous: HOMEWORK