首页 > 其他 > 详细

LCS problem using Binary-Search\Rolling hash

时间:2014-12-20 10:23:38      阅读:183      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/tonix/p/4175075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!