18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

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.

Approximate String Matching<br />

Figure: Example dynamic programming matrix for edit distance computation, with the optimal alignment path highlighted<br />

in bold<br />

Once you accept the recurrence, it is straightforward to turn it into a dynamic programming algorithm that creates an<br />

matrix D, where n = |P| and m = |T|. Here it is, initialized for full pattern matching:<br />

EditDistance(P,T)<br />

1]+1 )<br />

(*initialization*)<br />

For i = 0 to n do D[i,0] = i<br />

For i = 0 to m do D[0,i] = i<br />

(*recurrence*)<br />

For i = 1 to n do<br />

For j = 1 to m do<br />

D[i-1,j]+1, D[i,j-<br />

How much time does this take? To fill in cell D[i,j], we need only compare two characters and look at three other cells.<br />

Since it requires only constant time to update each cell, the total time is O(mn).<br />

file:///E|/BOOK/BOOK2/NODE46.HTM (2 of 3) [19/1/2003 1:28:46]

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

Saved successfully!

Ooh no, something went wrong!