原始Boyer-Moore与Boyer-Moore-Horspool算法的区别

时间:2013-09-06 08:07:59

标签: algorithm pattern-matching boyer-moore

我无法理解Horspool在其算法中所做的更改。如果您有Boyer-Moore-Horspool算法的任何链接,请告诉我。

2 个答案:

答案 0 :(得分:4)

以下是我的几点意见:

<强> BM:

Preprocessing complexity: Θ(m + σ)

Worst Case : Θ(nm) If pattern exists Θ(n+m) If pattern doesn't exist" 
Best Case : Θ(n/m) 
Space: Θ(σ) 
Comparisions: Θ(3n)

Preprocessing: Uses Good Suffix and Bad Character Shift.

Probably the fastest non-indexed text-search algorithm known.  
Works better in natural text and larger text searches.

A little difficult to implement.

Mostly used.

<强> BMH:

Preprocessing complexity : Θ(m + σ)

Worst Case : Θ(nm)
Best Case : Θ(n)
Space : Θ(σ)
Comparisons : Θ(1/σ) to Θ(2/σ+1)

Preprocessing:

Recommends to Use only Bad Character Shift.

Efficient for small alphabets

Easy to implement.

答案 1 :(得分:1)

我想wikipedia entry说明了一切。

编辑:
根据条目中的one of the external links

  

Boyer-Moore算法中使用的坏字符转换(参见Boyer-Moore算法章节)对于小字母表效率不高,但是当字母表与图案的长度相比较大时,因为它通常是使用ASCII表和在文本编辑器下进行的普通搜索的情况下,它变得非常有用。   单独使用它可以在实践中产生非常有效的算法。 Horspool建议只使用窗口最右边字符的坏字符移位来计算Boyer-Moore算法的变化。

     

预处理阶段是O(m + sigma)时间和O(sigma)空间复杂度。

     

搜索阶段具有二次最坏情况,但可以证明一个文本字符的平均比较数在1 / sigma和2 /(sigma + 1)之间。