Unformatted text preview: Introduction to Algorithms
Massachusetts Institute of Technology
Professors Erik Demaine and Shaﬁ Goldwasser February 24, 2004
Handout 7 Problem Set 3 Reading: Chapters 8.1-8.3, 31.1-31.5, 31.7-31.8
There are four problems. Each problem is to be done on a separate sheet (or sheets) of paper.
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. Giving an
1. A description of the algorithm in English and, if helpful, pseudocode.
2. A proof (or argument) of the correctness of the algorithm.
3. An analysis of the running time of the algorithm.
It is also suggested that you include at least one worked example or diagram to show more
precisely how your algorithm works. Remember, your goal is to communicate. Graders will be
instructed to take off points for convoluted and obtuse descriptions. If you cannot solve a problem,
give a brief summary of any partial results. Problem 3-1. Min and Max
Suppose we wish to ﬁnd both the minimum and maximum values in an array of distinct elements.
To individually ﬁnd either the minimum or maximum, there is clearly a
lower bound on
comparisons, since we must compare every element at least once. We can save a comparison by
ﬁrst scanning for the minimum, removing it, then scanning for the maximum. This takes a total of
¡ ¨ ¢
©§¡ ¦ Based on this observation, prove the following statement true or false: ¢
¡ ¦ “It takes at least
comparisons, for some constant , to ﬁnd both the minimum and the
maximum in an array of distinct elements.” ¡ Problem 3-2. Monotone Priority Queues
A “monotone priority queue” (MPQ) is a data structure that supports the following operations: M IN ( ) - Returns the minimum element in . The minimum of a new, empty MPQ is
. Otherwise, the minimum of an empty MPQ is the last element deleted. I NSERT (
" given that M IN . If ' %
" &$# into M IN %
)(# ) - Inserts , then the MPQ is not
¢ Handout 7: Problem Set 3 2 D ELETE -M IN ( ) - If is empty, returns the minimum. Otherwise, removes and returns the
minimum from . If the queue is empty after the operation, the last deleted value remains
the minimum. In other words, the minimum value is monotonically increasing and does not
reset when the MPQ is empty. -time to perform op- time to % % # ¨
¨ § (b) Give an implementation of a monotone priority queue that takes
perform total operations. Hint: Use an idea from C OUNTING -S ORT . ¨ ¡
¢ (a) Implement a monotone priority queue that takes
erations starting with an empty data structure. for some ﬁxed integer value . ¥ £
¦¤ is an integer in the range £ For this problem, assume that # £
¨ § ¨ (c) 6.046 student Ben K. Bitdiddle has invented a MPQ that operates on any totally ordered set, rather than just integers in the range
. A total ordering deﬁnes a
relation for all pairs of elelments in a set.
Ben claims that his MPQ can perform operations in
classmate Alyssa P. Hacker quickly dismisses his claim as impossible. Explain who is
correct and prove why. " ¥ £
¦¤ % # ¨
! § ¨ Problem 3-3. Operations on Elliptic Curves
Throughout this problem we will be discussing operations on elliptic curve points. You do not
need to know any speciﬁcs about elliptic curves or their operations. The basic operand will be
points denoted by bold capital letters, for example P.
You are given a subroutine A DD which can add points, for example A DD (P,Q) = P + Q. You may
-time, where P has an -bit representation.
assume that A DD runs in ¡ % #¡ § Multiplying an elliptic curve point P by a scalar is equivalent to adding P to itself
That is, P = P + P, P = P + P + P, etc. By this deﬁnition, ( P + P) =
P = ( P + P). %¤ ¢ #
& % ' % ¦ $¡#
2 # '
% ' % -time 0 % £ % -time scalar multiplication algorithm. ¦ ¦ ¨ % % $¡#
3 0 (b) Give an % (a) Suppose you are given a -bit integer and a point P as inputs. Give a
scalar multiplication algorithm that computes P using only calls to A DD . (c) Ben K. Bitdiddle, notices that his solution to part (b) always makes between and
calls to A DD . He thinks he can improve on this and writes a point doubling procedure
D OUBLE that runs in
time. The output of D OUBLE (P) is P.
Rewrite your solution to part (b) using D OUBLE . What are the new upper and lower
bounds on the runtime? What is the expected number of calls to A DD if is chosen
uniformly at random from
£ £ ¦ % #¤ % 1 % ¤"¢ ¦ #
A ¨ ¦ ¤ 6
7 § ¡
54 (d) Ben gets the idea to pre-compute the values P, P, P, ,
P and store them in
an array such that
P. Suppose you naively ﬁll in the array in
-time scalar multiplication algorithm. You
by repeated point addition. Give an
may assume that divides
and may use both D OUBLE and A DD in your code. % ¦ $¡#
A § B 8 8
E ¥ D 1 % #
G § B %¤ ¢ #
P I Handout 7: Problem Set 3 3 £ I ¦ $¡# 1 % @
# @ G . Include both the ¢ § % B Problem 3-4. Man on the Moon % #¡ (e) Give a value of such that the algorithm in part (d) runs in
time it takes to ﬁll and compute P, i.e.
. Alyssa ( ) wishes to determine whether her -bit string is the same as Ben’s ( ) -bit string
. Unfortunately, Ben lives on the moon and communication costs are very high. Ben devises a
scheme to determine with high probability whether or not
, while minimizing communication. Let and denote the th bits of and ’s respective representations: ¡ ¡ £ ¦ " !
0# ( %¤ ¤ ¡ # % #
G¤ ) E
$ roots, if £ % # 1E
2¡ ¡ £ % # % # ¡
B ¡ B %
('& B ¢
¢ E % # ¡ % # £ ¡ (a) Given that a -degree polynomial can have at most
maximum probability that Ben accepts? £ ¡ E . . , , and to ¦ # % # ¦ and accepts if , denoted
¥¡ computes , and sends . % ¤ ¡ £ 5. , denoted ¢
¦ " !
$# ¡ ¦ ' ©' ¨¡
¤ D deﬁnes a -degree polynomial over . ¤ ¡ £ 4. E and computes £ B 3. picks a random ¡ 2. deﬁnes a -degree polynomial over ¡ 1. picks a prime such that . what is the ¡ (b) Give an explicit upper bound (in terms of ) on the number of bits transmitted in this
scheme. Do not give an asymptotic upper bound, but rather an actual function, e.g.
. ¡ % 4$¡#
§ ¡3 §
§ Alyssa suggests a second scheme:
times: ¢ . % % 1$ ¦0"9 !
¦ % ¦0"# [email protected]# %
# % ¦ " ! ¡
$ # B # ¦ "
$9 ! £ ¦ ¢ # B accepts if ¤ ¢ 2. 5
6 (a) picks a prime uniformly at random from the range
(b) sends and
(c) rejects if ¥ £ 1.Repeat for all steps. (c) Assume that there are primes less than , that is
, give an upper bound on the probability, in terms
of and , that
for all rounds. You will need to use the
Chinese Remainder Theorem. % 5
¥H' ' F ¦
98 8 ' § ' # ¦
C ¦ £ 5 % £ ¦ "
T9 ! £ 1E
E¡ # ¦T"9 87
S F P
G E % ¦B # % ¦ F¤ 7I#
B £ (d) Using the the Prime number theorem in CLRS Section 31.8, upper bound the probability of failing all rounds of the protocol in terms of and ? 5 £ £ ...
View Full Document
- Spring '04