Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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.

posted on 2014-12-20 09:40  Tonix  阅读(291)  评论(0)    收藏  举报