01.04.2015 Views

Sequence Comparison.pdf

Sequence Comparison.pdf

Sequence Comparison.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.4 Dynamic Programming 31<br />

Fig. 2.12 Tabular computation of the length of an LCS of 〈A,L,G,O,R,I,T,H,M〉 and<br />

〈A,L,I,G,N,M,E,N,T〉.<br />

work. These arrows will guide the backtracking process upon reaching the terminal<br />

entry (m,n). Since the time spent for each entry is O(1), the total running time of<br />

algorithm LCS LENGTH is O(mn).<br />

Figure 2.12 illustrates the tabular computation. The length of an LCS of<br />

and<br />

〈A,L,G,O,R,I,T,H,M〉<br />

〈A,L,I,G,N,M,E,N,T 〉<br />

is 4.<br />

Besides computing the length of an LCS of the whole sequences, Figure 2.12<br />

in fact computes the length of an LCS between each pair of prefixes of the two<br />

sequences. For example, by this table, we can also tell the length of an LCS between<br />

〈A,L,G,O,R〉 and 〈A,L,I,G〉 is 3.<br />

Algorithm LCS OUTPUT(A = 〈a 1 ,a 2 ,...,a m 〉, prev, i, j)<br />

begin<br />

if i = 0or j = 0 then return<br />

if prev[i, j]=“↖” then<br />

LCS OUTPUT(A, prev, i − 1, j − 1)<br />

print a i<br />

else if prev[i, j]=“↑” then LCS OUTPUT(A, prev, i − 1, j)<br />

else LCS OUTPUT(A, prev, i, j − 1)<br />

end<br />

Fig. 2.13 Delivering an LCS.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!