## Monday, July 5, 2010

### Dynamic Programming Practise Problem Set 1

1.  Suppose we want to make change for n cents, using the least number of coins of denominations 1, 10, and 25 cents. Describe an O(n) dynamic programming algorithm to find an optimal solution. (There is also an easy O(1) algorithm but the idea here is to illustrate dynamic programming.)
2.   Here we look at a problem from computational biology. You can think of a DNAsequence as sequence of the characters “a”,”c”,”g”,”t”. Suppose you are given DNA sequences D1 of n1 characters and DNA sequence D2 of n2 characters. You might want to know if these sequences appear to be from the same object. However, in obtaining the sequences, laboratory errors could cause reversed, repeated or missing characters. This leads to the following sequence alignment problem. An alignment is defined by inserting any number of spaces in D1 and D2 so that the resulting strings D01 and D02 both have the same length (with the spaces included as part of the sequence). Each character of D01 (including each space as a character) has a corresponding character (matching or non-matching) in the same position in D02. For a particular alignment A we say cost(A) is the number of mismatches (where you can think of a space as just another character and hence a space matches a space but does not match one of the other 4 characters). To be sure this problem is clear suppose that D1 is ctatg and D2 is ttaagc. One possible alignment is given by: ct at g tta agc In the above both D01 and D02 have length 8. The cost is 5. (There are mismatches in position 1, 3, 5, 6 and 8). Give the most efficient algorithm you can (analyzed as a function of n1 and n2) to compute the alignment of minimum cost. 1
3. You are traveling by a canoe down a river and there are n trading posts along the way. Before starting your journey, you are given for each 1 i < j n, the fee fi,j for renting a canoe from post i to post j. These fees are arbitrary. For example it is possible that f1,3 = 10 and f1,4 = 5. You begin at trading post 1 and must end at trading post n (using rented canoes). Your goal is to minimize the rental cost. Give the most efficient algorithm you can for this problem. Be sure to prove that your algorithm yields an optimal solution and analyze the time complexity.
4.  For bit strings X = x1 . . . xm, Y = y1 . . . yn and Z = z1 . . . zm+n, we say that Z is an interleaving of X and Y if it can be obtained by interleaving the bits in X and Y in a way that maintains the left-to-right order of the bits in X and Y . For example if X = 101 and Y = 01 then x1x2y1x3y2 = 10011 is an interleaving of X and Y , whereas 11010 is not. Give the most efficient algorithm you can to determine if Z is an interleaving of X and Y . Prove your algorithm is correct and analyze its time complexity as a function m = |X| and n = |Y |.