Due 05.May.11 (Wed) 17:00.
We will award up to 15pts of extra credit on
the following problems.
(If you turn in more than 15pts worth, we'll grade the first 15pts
we feel like and stop.)
Note:
These problems are to be completed by yourself,
not with a partner.
Turn in your problems as ordered in the list below
(and include the problem# from here as well as from the book), thanks.
Otherwise, the usual
hw
policies
apply
On these problems more than ever, we will be looking (and grading) for a high level of understanding, clarity, and conciseness. In general, extra-credit problems are harder work for fewer points (but cover interesting, more in-depth material). Note that some of the problems require reading sections of the book we didn't cover in lecture (Huffman codes, posets ("partially-ordered sets")).
(2 pts) Look up on the web, Warshall's algorithm generalized to compute not just the transitive closure of a graph, but the shortest path between any two pairs of vertices.
What is the loop invariant, for this variant of Warshall's? Do p.507 #28b with some made-up initial distances, and the modified algorithm.
When looking at divide-and-conquer algorithms, our sub-problems were often of the size ceiling(n/b) or floor(n/b). However, in our analysis (Th'ms 1,2 of 6.3) we presumed the recursive calls were of size exactly (n/b).
Does this matter, for the final big-Oh results? Argue why or why not, proving your statements.
A two-dimensional array A is symmetric if A[i][j] = A[j][i] for all valid indices i,j. You can see that an implementation of a symmetric-array class, rather than allocate N2 locations, could instead allocate only N(N+1)/2 locations (about half), and have its own lookup method.
One way to do this would be to use the first index as an vector-of-vectors, where the ``inner'' vectors range in size from 1 to n. (``vector'' meaning a one-dimensional array.) However, this means an array lookup takes two memory references (one for each vector). Depending on cache sizes and how the array is used, this could cause an excessive amount of cache misses.
A more memory-stingy approach would be to internally have just a single vector, and to translate the user's i,j requests to a single index into the interal vector. This requires some index arithmetic, but fewer memory addresses.
This problem generalizes beyond two dimensions: an m-dimensional array A (size Nm) is symmetric if, for lists of m indices idxs1 and idxs2, A[idxs1] = A[idxs2] whenever idxs1 is a permutation of idxs2. (You can think of sorting the list of indexes before doing the lookup.)
(1.5pts) First, look at some sites like tinyurl.com or snurl.com which take long URLs and create new short names for them. You might wonder how quickly such sites will run out of short names.
If there are 1010 static web pages, and every single one of them were registered on such a site, how long would be the longest small URL be? (Just count the encoded part of the name, without the initial ``http://www.snurl.com/'' prefix.)
We might then start to wonder, is 1010 a reasonable upper estimate on the number of web pages? After all, one of the best use of these sites is for abbreviating dynamic URLs which contain (long) queries embedded inside them (e.g. mapquest URLs). So we'll ask the same question, but now suppose that 1010 people each generate one dynamic request per second, for 1010sec (about 325 years — e.g. since William of Orange took the English throne in 1688). How long will the longest short-URLs be now?
To think about to yourself:
Does one of these sites do a better job than the other?
Which do you prefer?
¹ if you ever (say) publish a shareware program where buyers receive a key upon payment, to unlock/register their copy of software.
[an error occurred while processing this directive] [an error occurred while processing this directive]