Hints
- Homework 1.
- Problem 2. You can be less detailed than trying to draw a
detailed decision tree for example. Also we know for example
that binary search on three keys takes 2 comparisons in the worst case.
You can use this directly. You can
for example say to binary insert a into b,c,d "I need 2 comparisons
and let the result of this binary insertion be x1,x2,x3,x4 in sorted order,
i.e. x1-x4 are the permuted a,b,c,d"
- Problem 4 This problem might be tricky (if you look the web, and
you are not supposed to do so, or the textbook) but is not supposed to be
tricky.
If you were told the keys were numeric,
think of the following case 1,2,3,4,5,1000,1001,1002,1003.
The median is 5 but the m=4 closest to 5 are 1,2,3,4.
However noone told you the keys were numeric, and you need to make
only a reasonable assumption about the m closest (in the sorted
sequence). This latter problem is much easier than the former (numeric
values). So i sort of expect 3,4,1001,1002 as an answer! Lucky you
I was not careful in formulating this problem.
- Problem 5 Part (a) is easy, (b) is really easy (but the
devil is in the details!) but (c) is very very tricky.
The solution of (a) might help you or mislead you for (c).
Pointwise i will assign more points to a careful solution to (a) and (b)
than (c). Say 20,20,10.
- Problem 6
Part (a) is easy and might give you hints for (c). Part (b) you might know
it already. We might say something on Tuesday through Subject 1, so a
solution might have to wait if you have not faced it before. Part (c)
is to help you clean up (a), (b) thoughts. It helps if you read (d)
as well, whose answer relates to (c). (You do the work in (c) to get
easy points in (d).) Part (e) is open-ended. Be minimal and if you
wish to spend too much time on it go to (f). The points for (f) will
be fewer than the other parts. In some sense it is optional. Think
binary in general.
- Problem 8
In the initialization code sample, there is a reference to a function random().
Such a function in C behaves differently from a similarly-named function in Java.
The former might return an integer (and this example assumes so) whereas the latter
returns a float. Be careful and do not get confused!
Oh and the Java supporters of you. Note that through the java virtual machine
you can change heap or stack size. Use java -X and you can get a list of
interesting options. (On solaris systems i.e. afs stack size can be
as low as <1MB).
- All Problems 1-6 Do not try to write detailed code. You might
bogled down in details. Keep things abstract to a level. So to sort 4
keys with 5 comps in the worst case i could write.
'Let a,b,c,d are the 4 keys. Sort the first 3 with 3 comparisons the
way we did in class. Let the sorted three keys be x,y,z in sorted order.
Then Binary insert d into x,y,z in 2 more comparisons. done."
- Homework 2.
- Problem 1.
- Problem 2.
- Problem 3.
- Problem 4.
- Problem 5.
- Problem 6.
- Problem 7.
- Homework 3.
- Problem 1.
- Problem 2.
- Problem 3.
- Problem 4.
- Problem 5.
- Problem 6.
- Problem 7.
- Homework 4.
- Problem 1.
Read HW1 Problem 6 carefully! First try to find a solution as close to O(lg^3 (n)) as possible.
If you cannot find
a solution that is O( lg^3 n) say with a YES or NOT whether you think such a
solution exists or not (for example flip a coin and say YES or NO). Then figure out the same
for O(M(lgn)) i.e. O(lg^2 n).
- Problem 2. A right parenthesis is missing from M(n)=Theta(n^lg7 in the last line of that
problem. Apply the iteration method carefully. Explore variations for the base case!
- Problem 3.
The running time is the hint!
- Problem 4.
The running time is the hint!
- Problem 5.
If you took part in our NJIT 2012 High School Programming Contest this problem might look familiar
but it shouldn't (the HSPC problem was diffferent).
The problems asks for "minimum collection of stamps". It is supposed to mean,
and admittedly it is not very clear, the minimum number of stamps s and also
how many of each type, s1,s5,s6 such that s=s1+s5+s6. Note that even if
only s was asked, deriving s1,s5,s6 would not be difficult (i.e. O(n)).
- Problem 6.
Pay attention to class on March 20. All the tricks needed were used in class.
BTW the "and the inverse (which is obvious)" is to mean "and the other way around
(which is obvious)". I.e. that if you can multiply (arbitrary matrices) you can triangular
multiply (which is obvious given that triangular matrices are an instance of arbitrary matrices).
- Problem 7.
Same as in Problem 6. Read the book for more details. For Problem 7, in various places such as
the sum X= 1+A + ... or X=1+Z ... , a 1 pops up as the first term. This 1 is I the identity
matrix of order n, i.e. n rows and columns with 1 in the diagonal and 0 everywhere else.
The Conclusion (no proof needed) is a statement of my own that concludes the solutions of (a)
and (b) if given by you. You don't need to prove the conclusion. To show that C_t (n) is
O(M(n)) is non-trivial and taking a CS 341 class might help you dealing with a solution: For this
i kept it out of the problem.
- Problem 8.
- Problem 9.
- Problem 10.
You are allowed to use BigInteger in Java.
Last modified Mon Mar 26, 2012, 09:20