hari6988's blog

By hari6988, 15 years ago, In English
I was studying the Longest common substring problem using DP ...

LCS(s1--p, t1--q) = 1+ LCS(s1--p-1, t1--q-1) if s[p]=t[q]

                                 0 otherwise

This was the solution given in wikipedia... This would give an answer of 0 for the strings "to" and "tom" ... But, shouldnt it be 2 ?? the "to" matches with "to" in tom . But, it compares only the last character and gives the answer`
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
15 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
LCS(1,1) = 1
LCS(2,2) = LCS(1,1) + 1 = 2
Other LCS(i,j) = 0
So it seems to be right.