184
Chapter 9
I
Dynamic programming
They’re both the same: two letters! But
fosh
is closer to
fish
.
You’re comparing the longest common
substring
, but you really need
to compare the longest common
subsequence
: the number of letters in
a sequence that the two words have in common. How do you calculate
the longest common subsequence?
Here’s the partial grid for
fish
and
fosh
.
Can you figure out the formula for this grid? The longest common
subsequence is very similar to the longest common substring, and
the formulas are pretty similar, too. Try to solve it yourself—I give the
answer next.
Dostları ilə paylaş: