Hints
- Homework 1.
- Problem 1.
- Problem 2.
- Problem 3.
You may assume all the integers are distinct and so are their sums
(note that in the example, even if the numbers were distinct the sums were not).
- Problem 4.
- Problem 5.
There has been some confusion about the 'implement the first step'. You are not asked to write
a program, just to show how this can be done (in pseudocode, English description, etc).
- Problem 6.
For this problem you have 16 different arrays (for 4 sizes, and
4 input distributions) BUT the same array should be fed into all 4
algorithms in each one of the 16 cases. So be careful with the random case.
You can't have in one algorithm '3 random keys' such as
103 41 51 and in the other the '3 random keys' become 54 1023 345 because
you generate them from scratch again.
If the 103 41 51 is the input to qsf so should it be for qsl and so on.
One easy way to achieve this for this problematic (ie random) case is you to seed
the random number generator. See the information of P7/Issue 2 below.
- Problem 7/ISSUE 1.
There are some issues with the paragraph "Test your 4...".
(a) hw1dump.txt contains the input keys. So if the input keys are storted in A,
and are 20 30 10 40 and the function call is to find the minimum (1-st order statistic) the
index returned is 2 that contains A[2] (i.e. 10), the minimum. If you plan to reorder the input keys,
be careful where your point to. (b) "...for each of the 5 runs...". There are 4 runs since there are
4 functions. The input to each one of the should be the same so that there is consistency in comparing
running times!
- Problem 7/ISSUE 2 (new).
Some of you asked how random if called from the outside i.e. hw1 1 2 3
and hw1 3 2 3 can use the same array for input in to separate
sorting operations. There are a
variety of ways to deal with this easiest to hardest. The easy: when you
use a random number generator you pick its seed. Thus a default
Random() vs a non-default Random(seed) will have varying behavior.
The former will use as a seed the current time (most likely) and the
latter your choice of a seed (and 0 is NOT a good choice).
For example, JAVA says public Random() { this(System.currentTimeMillis()); }
Alternatively make sure you reuse the input previously used
(think of problem 6 and the dump file). Another way is to ignore altogether
(AND THIS IS ACCEPTABLE)
the first argument (the algorithm) and run ALL 4 of them in a single
call for a given input distribution and problem size. But then be careful:
make sure the second run (and in the order qsf,qsl, this means qsl) does
not use the output of the previous run because a random input after it
becomes sorted (in average case running time) becomes a worst-case input
for the second run.
- Problem 7/ISSUE 3 (Tue Feb 12).
For the benchmarking part of 4 x 3 (4 algorithms, 3 problems sizes), i did not specify
what the statistic you plan to use should be. Pick the median or something close to it
(floor((n+1)/2) for example). Also if you plan to run all 4 algorithms on the same input,
use one or four dump files as you see fit.
- Homework 2.
- No issues
- Homework 3.
- Problem 1. Some of you asked for the cost of matrix multiplication.
If you don't know (and we will formally do it/skip it next week), multiplying
two kxk matrices requires O(k**3) operations (mults and adds) or in
particular k**3 = k^3 mults, and k**2 * (k-1) = k^3 -k^2 = k**3 - k**2 adds.
- Problem 3.
It is mentioned that C contains integers between 0 and 30n. It should
have been between 0 and 60n, since A,B are between 0 and 30n. And
the HINT is not much of a hint. It says represent polynomials to
degree 15n. Think more to 30n instead.
- Homework 4.
- Problem 1.
- Problem 7.
Some issues
- Storage The n is the dimension of a square n x n array i.e. n **2 elements.
A(i,j) is stored into a one dimensional array A(j*n+i) for efficiency.
- Input/Output All n elements in one line. It's not my intention to cause difficulties, but bear
in mind that if you have a 16x16 array a human might put 4 or 8 elements in a line;
not all 16 might fit.
- Typo last line The last line (benchmarking points) is supposed to read 20 of the 60 not 25 of
the 75.
- Set Matrix It might help you to have it in case you plan to use ReadMatrix twice to
read the same matrix (A or B). Reading from a file is slow, thus if you plan to initialize
A and B, it is better if you read from a file once (per matrix), copy into memory space,
and the do a memory copy with SetMatrix.
- Homework 5.
- Problem 1.
For mergesort use T_s = c n lgn, c a constant c>=1 and for bubble
sort use T_s = c n**2 , c a constant c>0, to express sequential running times.
When you compute speed ups figure out the most important component and ignore lower order terms.
Note also that for (a).(i) the p is equal to sqrt(n). In the pdf copy sometimes the square root
is not drawn properly.
- Problem 3.
Think all of Thursday discussion from the start to the very very end.
- Problem 5.
Number of hits is all the documents returned. Out of all those documents you only
examine the first 20 'hits'. Out of those 20 you need to identify the relevant documents;
any document addressing CS 667 Design Techniques for Algorithms is relevant. Althought there
may be other CS 667 courses elsewhere the "CS 667 Design Techniques for Algorithms" is
unique!
For calculation of efficiency and recall ignore decimal digits (ie take floors).
To compute precision at a given recall pick the closest available, do not interpolate,
if at 22% recall you have x1 and at 35% recall you have x2 and you want to compute the
precision at 25% pick x1; to compute precision at 30% pick x2, instead of trying to obtain
a more accurate value between x1 and x2.
- Problem 6,7,9.
If you plan to implement code for Problem 9 or just to solve Problems 6,7 use the example
of Problem 9 for calibration and validation. Be careful when you terminate the iterations.
Less than 10**-4 does not mean equal. Usually maintaining 5 digits of precision suffices
to figure out when to stop.
- Homework 6/EX1.
- Problem 1. Express answers in terms of n and m and thus patterns must be in terms on n and
m in the alphabet of your choice
- Problem 2. If you do (b) first you can't claim credit for (a). You need to give two
different algorithms. The bounds given are not tight to give you some leeway.
- Problem 4. Be precise mean an answer O(n) is not good enough. An answer
234n + o(n) is not good either. 10n+7lgn -3 is precise, for example.
- Problem 5. Answer (a) first ,then (b) and then (c). Note that for (a) you need to
GIVE A PROOF one way or the other!
Last modified May 6,2013, 11:10