In the first question of this assignment there is no programming - for those you should write up your answers (proofs or analyses) in a plain-text, pdf or Microsoft Word file and submit it as part1.txt, part1.pdf or part1.doc. For the second problem, you will submit 4 files: 3 code files (align.scm, Align.java and align.pl) and 1 text file (part2.txt). For the third problem, you should submit Wally.java. Again, zip all of these files into a single file called hw13.zip.
Watch out because Sakai only allows you to submit your assignment ONCE. So, IF YOU ARE TAKING A LATE DAY, you must let me know so that I can enable resubmission after you submit the Wally problem on 12/12.
You may use your remaining late days on this assignment, except
for problem #3,
the Wally problem. Since we will talk about that program on Thursday,
December 13 in class,
there are no late days available for that one.
Professor Dee Videnconker has proposed the following
alternative approach to multiplying two n-bit numbers x and y.
Notice that x has n/2 "upper bits" which we'll call "a" and n/2 "lower
bits" which we'll call "b". Similarly, dividing y in two parts gives us
the upper n/2 bits, which we'll call "c", and the lower n/2 bits, which
we'll call "d". So, x = a 2^{n/2} + b and y = c 2^{n/2} + d. What's
going on here? Notice that multiplying "a" by 2^{n/2} "shifts" it by
n/2 positions. The number "a" by itself is a n/2 bit number. After the
multiplication by 2^{n/2}, the bits of "a" have been "promoted" so
that we now have a n-bit number in which the first n/2 bits are the
bits of "a" and the last n/2 bits are all 0's. Now, adding "b" to this
gives us a n-bit number in which the first n/2 bits are "a" and the
second n/2 bits are "b". That is, we now have written x in terms of "a"
and "b". We do the analogous thing for expressing y in terms of "c" and
"d".
So, back to Professor Videanconker's algorithm! The algorithm works like this: Divide x into two n/2-bit numbers "a" and "b" and similarly divide y into two n/2 bit-numbers "c" and "d". Now, xy = (2^{n/2}a + b)(2^{n/2}c + d) = 2^{n}ac + 2^{n/2}(ad + bc) + bd. We compute "ab" using a recursive call (now on numbers that are n/2 bits long!) and similarly we compute "ad", "bc", and "bd". After the recursive calls are complete we do the multiplications by 2^{n} and 2^{n/2} followed by some addition.
Notice that multiplying by 2^{k} is just the same as adding k 0's to the end of the number. This can be done in k time steps. Similarly, adding two j-bit numbers can be done in j time steps.
temp1 = (a+b)(c+d)Nothing for you to do here! This is just the description of the algorithm.
temp2 = ac
temp3 = bd
z = temp2 2^{n} + (temp1 - temp2 - temp3) 2^{n/2} + temp3
The problem you will address is the problem we looked at on the first day of class: the problem of DNA sequence alignment (taken from a homework assignment by Sedgewick and Wayne: http://www.cs.princeton.edu/courses/archive/fall07/cos126/assignments/sequence.html). Follow the link and read the assignment up through the part where it talks about how to measure the distance between to sequences. Don't worry about the dynamic programming part (although you might want to read it as you might find it helpful in general... with other computational problems). We will not implement an algorithm for finding the minimum edit-distance alignment here. We will only implement the edit-distance function for two given lists of DNA sequences.
Part 2.1: Implementation (15 points)
Implement the following:
Part 2.2: Relection (20 points)
After you have written your code, imagine that you wanted to implement a complete solution to the sequence alignment problem (i.e., find the minimum edit-distance alignment). You don't actually have to implement anything, just think about how you would implement it. Also, you don't have to implement a fast algorithm--brute force is fine.
Now, choose the language that you feel would be best suited for this implementation, and write a short essay (2-3 paragraphs) explaining and defending your choice of language. You should address your argument to your classmates--that is, students currently in CS60. Try to convince them that your choice of language is the best choice based on your experience implementing the functions above and your thoughts about how you will implement the rest of the program. Be clear about your evidence. We will grade you on how convincing your argument is, taking into account how clear your examples are, and how clean your writing is.
In your argument, you may wish to consider any or all of the following:
You specifically should not worry about running time in this problem. Turn in this writeup in a file called part2.txt.
Extra Credit on this part: If you actually do implement the full optimal alignment program you will receive 5 points extra credit. Place the extra credit code in the same file as the code for the required section, and include a comment at the top of the file and in your writeup file.
The problem
Wally is unicycling back to Mudd (@ the southwest corner of the map)
after spending the
summer in New England (@ the northeast corner). A square grid has been
overlaid on the
map, with each cell containing a positive number -- namely, the number
of
strawberry-filled DonutMan donuts that Wall will need to consume in
order to have enough energy to pass through that cell.
Your task is to maximize donut conservation. And for this problem
specifically, you
should write
public static int minDonuts(int[][] map)
This method should return the minimum number of donuts needed to get
from the
NE corner of the input map to the SW corner. The rest is up to you... the algorithm, the software structure (other classes, other meethods), and the testing you do.
Example
For example, here is an image of a 5x5 donut-consumption grid and the
correct minimum
answer. Note that the start cell will be in the final spot in the first
row, or map[0][N-1], and that the destination
cell is in the final
spot of the first column, or map[N-1][0], where N
is the
length of a side of the square map.
Below it is the path that produced that answer:
The write-up
You should comment your code in order to explain how your algorithm
works, as usual.
However, you should also include a comment at the top of your
file that includes
Submission
Submit Wally.java as instructed above, under
assignment #13.
Scoring
Your solution will receive full correctness credit if it runs in
"reasonable" time (under ten seconds on a 6x6 grid) and it works
correctly, i.e., it computes the true minimum donut cost. Slow correct
solutions will receive almost all of the points (unless they are
bogosort-slow). Incorrect solutions, fast or slow, will receive almost
no points.
The other half of the credit will be for your algorithm deisgn (not
speed, just thoughtfulness), explanation, program design, and
commenting.
Extra Credit Options