首页 > 代码库 > LCS problem using Binary-Search\Rolling hash
LCS problem using Binary-Search\Rolling hash
One TopCoder article introduces a very interesting alternative solution to Longest Common Sequences problem.
It is based on this statement (http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=stringSearching):
The important point that allows us to use BS is the fact that if the given strings have a common substring of length n, they also have at least one common substring of any length m < n. And if the two strings do not have a common substring of length n they do not have a common substring of any length m > n
So we can start b-search on string length of s1, for s2, since current substr len is fixed, we use rolling-hash to check match. Also, another interesting point to handle collision in a typical BK algorithm: we use double hashing to avoid collision, instead of a O(n) brutal-force string comp mentioned in EPI-300.
LCS problem using Binary-Search\Rolling hash