Introduction to Algorithms
October 1, 2004
Massachusetts Institute of Technology
Professors Piotr Indyk and Charles E. Leiserson
Problem Set 2 Solutions
Chapters 5-9, excluding 5.4 and 8.4
Both exercises and problems should be solved, but
only the problems
should be turned in.
Exercises are intended to help you master the course material. Even though you should not turn in
the exercise solutions, you are responsible for material covered in the exercises.
Mark the top of each sheet with your name, the course number, the problem number, your
recitation section, the date and the names of any students with whom you collaborated.
You will often be called upon to “give an algorithm” to solve a certain problem. Your write-up
should take the form of a short essay. A topic paragraph should summarize the problem you are
solving and what your results are. The body of the essay should provide the following:
1. A description of the algorithm in English and, if helpful, pseudo-code.
2. At least one worked example or diagram to show more precisely how your algorithm works.
3. A proof (or indication) of the correctness of the algorithm.
4. An analysis of the running time of the algorithm.
Remember, your goal is to communicate. Full credit will be given only to correct algorithms
which are described clearly
. Convoluted and obtuse descriptions will receive low marks.
Do Exercise 5.2-4 on page 98 in CLRS.
Do Exercise 8.2-3 on page 170 in CLRS.
Randomized Evaluation of Polynomials
In this problem, we consider testing the equivalence of two polynomials in a ﬁnite ﬁeld.
is a set of elements for which there are addition and multiplication operations that satisfy
commutativity, associativity, and distributivity. Each element in a ﬁeld must have an additive and
multiplicative identity, as well as an additive and multiplicative inverse. Examples of ﬁelds include
the real and rational numbers.
has a ﬁnite number of elements. In this problem, we consider the ﬁeld of integers
. That is, we consider two integers
to be “equal” if and only if they have the same
remainder when divided by
, in which case we write
. This ﬁeld, which we denote as
, . . . , p