Hints
Final Exam Hints at the bottom
- Homework 1
- Comment 1 Some of you mentioned the book by Knuth
(The Art of Computer Programming) as containing material on sorting
networks. Beware! Knuth has a different definition for a bitonic
sequence. In addition Knuth's version of bubblesort works the opposite
direction from the one of page 38 of CLRS.
- Comment 2 For the last problem, do not forget that the bitonic
sorter sorts bitonic sequences.
- Comment 3 For problem 3 consider the case that there exists
a sorting network that contains no comparator between m and m+1 and derive
a contradiction. This textbook problem is located after the 0-1 Sorting Lemma.
- Comment 4 For problem 5 try to answer the following
question. If an output line x is at level m (i.e. the maximum number
of comparators from any input line to output line x is m) how many inputs
lines (at most) are reachable from x?
- Homework 2
- Comment 1There is a typo in Problem 1.
The correct form of the S(n) recurrence is
S(n) =2 S(n/2)+ (nlgn)/2. The 1/2 factor is MISSING from Homework 2.
Use this form of the recurrence. Note that
for S(n) =2S(n/2) + nlgn even the boundary condition is false as
from the recurrence S(2)=2 S(1) + 2 = 2x0+2 =2 which contradicts
the given S(2)=1.
Apologies for the confusion.
- Comment 2For problem 4, try to solve the recurrence for
the general case where T(2)= C, where C is come constant.
What do you observe? Use this observation to solve problem 5.
- Comment 3For problem 5, if n= 2**p m, try to find
a constant d such that p = floor (lgn -d). Then how big can m be?
What is the base case? How do you multiply base case matrices? Use
the observation of Problem 4 to answer this question. Note that in
general m may not be a power of 2.
- Comment 4 For problem 5,
and p = floor (lgn -d) and m= ceil( n / 2**p) try to find the optimal d.
You may need to use a calculator for this. d is a small
integer positive constant BTW. Do not forget the properties of the floor and ceiling functions
(page 51 of CLRS).
- Comment 5 In Problem 4, base case is the case of a recursive
algorithm that requires a direct solution rather than a solution through
an additional recursive call. For sorting networks the base case was
n=2 as sorting two keys required a single comparator network. n=1 was
also an alternative base case.
- Comment 6 In Problem 3, reorder the terms in m5 and m6 in
the statement i.e. use m5 = A11* (B12-B22) and m6 = A22*(B21-B11).
Apologies for the confusion.
- Homework 3
- Comment 1 Problem 1: All polynomials are of the
same unknown (or indeterminate) and this is x. The coefficients
are general (i.e. they are non zero and arbitrary).
The reason i gave problem 1 was for you to draw some conclusions
on what the best way to multiply polynomials might be; the
conclusion, although surprising is expected.
- Comment 2 Problem 2: If there is a point-value
representation for A(x) and let it be (xi, yi) find one for Arev(x)
such as (zi,wi) so that zi and wi can be derived from the xi and yi.
- Midterm (Exam 1)
- Problem 4
The problem is from the textbook first section on Polynomial
etc, last problem (or page 830 of CLRS). Do not let the
O(n lgn) bound confuse you. The problem is NOT about FFT.
Understand the hint and use it effectively.
The Cartesian sum definition is the one given in the problem
(and of course on page 830). Note the difference between
Cartesian sums and products (defined in the appendix, check
the index). The cartesian sum is a set of numbers, the product
is a set of pairs (of numbers).
- Problem 2 The size of a comparison network is
the number of comparators. This problem asks you more or less
to devise a method that finds the size of a comparison
network by: (1) switching every comparator to state N,
(2) forming a specific input (3)and concluding the size
of the network from the output of the network.
If you don't get confused (as some of you got with
Problem 1 in HW3), the problem has a one- or two-line
simple solution.
- Comment 3 (Clarification) In problem (1a) an expression
for M(n+1) is asked and in part 1b an expression for M(n). Neither
one is a typo (that meant to be the other). Remember that an
asymptotic bound needs to be established...
- Homework 4
- Comment 1 Problem 2: Note that this problem has
nothing to do with factoring. You are given m1 , m2 , ... , mk,
and are asked to find their product m. m1, m2, ... , mk, may
or may not be prime, may or may not be different.
- Comment 2 Problem 1: On page 12 of the notes,
Corollary 4, a qi appears
in the subscript of an lg. It is a typo. It should read lgqi. This
is the first expression after the phrase "The multiplication
involved requires".
- General Comment This is a non-homework related
comment. The News section contains an update on a typo found
in the notes. The typo is on the material that will be covered
in class today (Apr 2) and DOES NOT AFFECT HW4.
- Homework 5
- Comment 1 Problem 1a: Finding the floor or ceiling of
the lgn suffices as an answer.
- Comment 2 Problem 3d: A can be any integer/real prime or not.
N is not necessarily a prime number. A may or may not be a constant.
The intent of the problem is the higher one chooses A the lower the
probability is that p divides a-b. Therefore one would choose A
to be a very big constant or a function of n. But this is something that
should NOT concern you. Treat A as a a general parameter with no specific
value.
- Final Exam
- Due Date It is not Mar 12 as printed on the front
page (my silly cut-and-paste) but the May 14 elsewhere reported.
- KMP 1 In the KMP algorithm i,j start from the first position
of the text and the pattern respectively. Somehow in the KMP pseudocode
of Subject8
the initialization is i=1; this is valid if the text array
is T[1...n]. However in C/C++
arrays start from 0. It should have been i=0 instead to make sense with
the rest C/C++ assumptions of the pseudocode.
- KMP 2 How many positions do we shift the pattern in a mismatch?
j-f[j-1]. Note the assignment j=f[j-1] in the pseudocode which states
the same. There is a typo somewhere in the text that says
"We shift P right j-f[j] positions, and we continue". It should read
"We shift P right j-f[j-1] positions, and we continue".
- KMP 3 To eliminate confusion about comment KMP2 and KMP3 an updated
version of Subject 8 is on the Web (third version). Try to
differentiate between the implementation
of the algorithm (pseudocode) from its workings. It will make problem 7
easier.
- Irrelevant comment I have just received some e-mails
of yours sent long time ago (an e-mail was sent on Mon Mar 11).
If you receive a reply / acknowledgement don't get confused. Ignore it;
it was sent just to show that the delayed response was due to e-mail
problems. However be careful; if you plan to submit the
exam by e-mail, the course e-mail account is
alg667@cs.njit.edu or
alg467@cs.njit.edu.
- General Comment You may use without proofs (reference
is required, eg: "According to Problem 1 of HW 5") results
proven in Homeworks 1-5 and the Midterm in addition to the
class results.