|
Homework Assignments (from textbook, unless otherwise
indicated)
|
Exercise Set #1
(due Wed, Jun 6)
|
Exercise 1.2-2
(page 13). |
|
Exercise 1-1
(page 13). Omit the first two functions (lg(n) and sqrt(n),
and then fill in the 1-minute, 1-day, and 1-year columns only. |
|
Exercise 3.1-4
(page 50). |
|
A.
Show how to compute a125 (mod m) with
11 modular multiplications, making use of the fast exponentiation
algorithm discussed in class? Be sure to indicate
exactly where each multiplication occurs. |
|
B.
Show how to compute
b5 (mod m) using 3 modular multiplications.
Noting that 125 = 53, and show how to compute a125
(mod m) with 9 modular multiplications. (Your
result will demonstrate that fast exponential algorithm given in
class is not always optimal with regard to the number of
multiplications.)
|
|
|
Exercise Set #2
(due Friday, Jun 15)
|
Exercise
3-2
(page 58). You make use of the facts proven in class about the
relative rates of growth of logarithms, polynomials, and
exponentials in this problem, as well as in other problems. |
|
Exercise 3-3,
part (a) (page 58). Omit the functions containing lg*. |
|
Exercise 3-4,
parts (c) and (d) (page 59). |
|
C.
Use Stirling's Formula to obtain a good estimate of the value
of 32! (40 factorial). Then include the 1 + 1/(12n)
term to obtain an even better estimate. Write your answers in
scientific notation, with enough decimal places shown to distinguish
to two estimates. |
|
Page 36, exercise 2.3-1 |
|
D. Prove by induction on n that the recurrence
C(n) = d + C(k) + C(n-k-1),
where d is a constant and 0 < k
<= n-1,
C(0) = 0,
has solution C(n) = dn. |
|
E. Find a
solution to each recurrence below that is exact when n
is a power of 2, and a good approximation otherwise.
a) C(n)
= C(n/2) + 2n + 3, C(1) = 1.
b) C(n) = 2C(n/2)
+ n
lg(n), C(1) =
0.
c) C(n) = 4C(n/2)
+ 3n2, C(1) = 0. |
|
Page 86, Exercise 4.4, parts (a), (c), (e), (h).
(For those parts where the Master Theorem, or the extension to the
Master theorem given in class, is applicable, quote it to obtain a
solution of the form T(n) = THETA(g(n)) where
g(n) is some simple
function of n. When you quote the Master theorem, give the values
of a, b, E = logb(a), and f
(n); see page 73 of the text, or the handout on the Master Theorem.). If the Master
Theorem is
not applicable, solve the recurrence directly, again obtaining a
solution of the form T(n) = THETA(g(n)). |
|
|
Exercise Set #3 (due
Wednesday, Jun 20)
|
How many inversions are there in the array
a = (41 16 74 33 66 54)?
How many comparisons would straight insertion sort perform in
sorting this array? How many exchanges would it perform?
|
|
Exercise
6.1-6 |
|
Exercises 6.3-1 and 6.3-2 |
|
Exercises 6.4-1 (As in Fig 6.4, start with the heap just
after is has been constructed by build-max-heap. You may limit
yourself to illustrating the first three steps, where one step
consists of removing the root from the heap and then restoring the
remaining elements to a heap.) |
|
Exercise 6.5.7 |
|
F. How many inversions are there in the array
a = (41 16 74 33 66 54)?
How many comparisons would straight insertion sort perform in
sorting this array? How many exchanges would it perform?
|
|
G.
Consider the recurrence
C(n) = C(0.8n) + C(0.5n) + C(0.2n) +
n, C(1) = 1.
If the recurrence has a solution of the form
C(n) = a
nb
+ c
n
+ d
for some real numbers a, b, c, and d
(ignoring the fact that 0.8n, 0.5n, and 0.2n
may not be integers), what must the value of b be?
Compute your answer to two decimal places. |
|
H. Show how to merge three sorted arrays of length n/3
into a single sorted array of length n using close to 5/3n comparisons,
even in the worst case.
|
|
I.
Consider 3-way mergesort, in which an array of size n
is divided into three subarrays of equal size, and the three
subarrays are sorted by recursive calls to 3-way mergesort.
The recurrence for the number of comparisons becomes C(n)
= 3C(n/3) + (5/3)n, C(1) = 0, assuming n is a
power of 3, say n = 3k. Find an exact solution to
this recurrence, when n is a power of 3. (Your final
solution should involve only n, not k.) How does
the number of comparisons performed by 3-way mergesort compare to
the number performed by ordinary mergesort?
|
|
|
Exercise Set #4 (due
Wednesday, Jun 27)
|
Exercise
8.1-1. |
|
Exercise
8.1-3.
H. Illustrate
the process of partitioning the array
36 83 75
48 14 71 64 22 91 69 58
88 72
using the "one-sided" partitioning algorithm on page 146 of the
textbook. See Figure 7.1. |
|
I. Illustrate the operation of the partitioning algorithm
presented in class (see quicksort handout) to partition the array
36 83
75 48 14 71 64 22 91 69
58 88 72
using the middle element (64) as the pivot element. |
|
Illustrate the
entire selection algorithm (the one that runs in expected linear
time) for finding the 9th smallest element of the array
36 83
75 48 14 71 64 22 91 69
58 88 72
Use the partitioning algorithm presented in class (see quicksort
handout). Give the arguments passed to partition() on
each call and the value returned. Show the array after each
call to partition(). |
|
J. Say
partition() is applied to an array a of size n,
with distinct elements. Let us say that partition()
produces a bad split if either the left or the right subarray has
size less than n/4. What is the probability of a bad
split if we choose the pivot element as
a) a single random element from a?
b) the median of three distinct random
elements of a?
c) the median of five distinct random
elements of a?
d) the median of seven distinct random
elements of a? |
|
Exercise 9.3-1 |
|
Exercise 9.3-8
|
|
|
Exercise Set #5 (due Wednesday,
July 11)
|
Exercise
15.2-1 |
|
Exercise
15.4-1 |
|
Exercise 14.4-2 |
|
Exercise
15.4-5 |
|
Exercise 15-6 |
|
Exercise 15-7 |
|
Exercises K and L
|
|
|
Exercise Set #6 (due Wednesday,
July 18)
|
|