You are on page 1of 2

Sean Li CS 4820 Notes Spring 2013 Introduction to Algorithms Lecture 10 2/11/13 Sequence Alignment.

t. Suppose we have two words x = x1 xm and y = y1 yn . A matching between {1, . . . , m} and {1, . . . , n} is called an alignment if edges do not cross, i.e. for any two pairs (i, j) and (i , j ), we have i < i if and only if j < j . The goal is to nd an alignment of minimal cost, where the cost is obtained by charging for each unmatched node, i.e. the gap penalty, and ab for each (i, j) M . Dynamic Programming Solution. There are 3 possiblities for the last pair. Either: (1) xm is matched to yn , (2) xm is not matched, or (3) yn is not matched. For a proof of this trichotomy, suppose not, and there must be cross edges. Let opt(i, j) be the cost of the optimal alignment of x1 xi and y1 yj . Then looking at the three cases, we have opt(m, n) = min{opt(m 1, n 1) + mn , opt(m 1, n) + , opt(m, n 1) + }. With memoizing, this runs in O(mn). Shortest Path Problem in a Grid. Draw a grid with the letters xi on the x-axis and yi on the y-axis. A path needs to run from the origin (empty string) to the top right at each stage moving either north, east, or northeat. Then each path is an alignment. Thus one could apply something like Dijkstras algorithm. Shortest Path and Negative Weights. Recall Dijkstras algorithm. Usually assume edge weights are positive, it also can be changed to require non-negative edge weights. Does not work for negative edge weights, as a negative cycle could make a shortest path impossible. Also, consider in stock trading, we might have a cycle where we gain money by trading A for B, then B for C, then C for D, then D for A. Joke. A physicist and an economist are walking down a street. The physicist sees a 20 dollar bill on the ground. The economist says, Impossible, someone would have picked it up!

Simple Path Lemma. Assume there are no negative cycles, then there is a shortest path from any s to t that is simple, i.e. it has no repeated vertices. Proof by contradiction. Suppose there is a cycle, then it may be removed without lenghthening the path. BellmanFord Algorithm. Look for paths of length at most n 1. Let opt(i, v) be the length of a shortest path from v to t of length at most i. Suppose we have a set of points W of points of length i from t. Then recursively, opt(i, v) = min{opt(i 1, v), min {opt(i 1, w) + c(v, w)}.
wW

The nal answer is opt(n 1, s). This is O(n3 ) and actually O(nm). Can be encoded in matrix multiplication with min and + instead of + and .

Page 2

You might also like