Phase 1 - Build Table
In phase 1 the algorithm builds a table. For example this is the table built for the
two strings: the quick brown fox jumps over the lazy dog and sick fox is crazy.
| | sick | fox | is | crazy |
| | | | | |
the | | | | | |
quick | | | | | |
brown | | | | | |
fox | | | | | |
jumps | | | | | |
over | | | | | |
the | | | | | |
lazy | | | | | |
dog | | | | | |
Every cell in the table contains three values: \(D\), \(P\), and \(Q\), and an arrow, like this:
We define the score \(S\) for each cell as:
\[S = \max(D, P, Q)\]
The grayed cells in the first row and first column are initialized using the gap start
and gap extension penalties. The numbers for each remaining cell are calculated using
only values from the three cells, to the top-left, the top, and the left, of the current
cell:
\[D = S_↖ + \mbox{similarity}(word_←, word_↑)\]
\[P = \max(S_↑ + openingpenalty, P_↑ + extensionpenalty)\]
\[Q = \max(S_← + openingpenalty, Q_← + extensionpenalty)\]
Finally the arrow in the current cell is set to point to that cell which yielded the
highest of the current cell’s \(D\), \(P\), and \(Q\) values.