Questions tagged [boyer-moore]

The Boyer-Moore algorithm is a fast algorithm for the exact string matching problem.

The algorithm scans the characters of the pattern from right to left beginning with the rightmost character. During the testing of a possible placement of pattern P against text T, a mismatch of text character T[i] = c with the corresponding pattern character P[j] is handled as follows: If c is not contained anywhere in P, then shift the pattern P completely past T[i]. Otherwise, shift P until an occurrence of character c in P gets aligned with T[i]. This technique likely to avoid lots of needless comparisons by significantly shifting pattern relative to text.

84 questions
33
votes
3 answers

Boyer-Moore Practical in C#?

Boyer-Moore is probably the fastest non-indexed text-search algorithm known. So I'm implementing it in C# for my Black Belt Coder website. I had it working and it showed roughly the expected performance improvements compared to String.IndexOf().…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
27
votes
2 answers

When would you use KMP over BOYER-MOORE

I am currently learning about pattern matching algorithms and have come across these two algorithms. I have the following general ideas: KMP Compares text left-to-right Uses a failure array to shift intelligently takes O(m), where m is the length…
Eric
  • 1,356
  • 2
  • 14
  • 24
22
votes
1 answer

Boyer-Moore good-suffix heuristics

I understand how the bad character heuristics work. When you find the mismatched letter x, just shift the pattern so the rightmost x in the pattern would be aligned with the x in the string. And it's easy to implement in code. I think I also…
good_evening
  • 21,085
  • 65
  • 193
  • 298
19
votes
2 answers

Is there a Boyer-Moore string search and fast search and replace function and fast string count for Delphi 2010 String (UnicodeString) out there?

I need three fast-on-large-strings functions: fast search, fast search and replace, and fast count of substrings in a string. I have run into Boyer-Moore string searches in C++ and Python, but the only Delphi Boyer-Moore algorithm used to implement…
Warren P
  • 65,725
  • 40
  • 181
  • 316
14
votes
3 answers

When is Rabin Karp more effective than KMP or Boyer-Moore?

I'm learning about string searching algorithms and understand how they work but haven't found a good enough answer about in which cases Rabin-Karp algorithm would be more effective than KMP or Boyer-Moore. I see that it is easier to implement and…
E.K
  • 315
  • 1
  • 3
  • 6
10
votes
3 answers

Constructing a Good Suffix Table - Understanding an example

I'm really trying to understand an example on how to construct a good suffix table for a given pattern. The problem is, I'm unable to wrap my head around it. I've looked at numerous examples, but do not know where the numbers come from. So here…
yulai
  • 741
  • 3
  • 20
  • 36
9
votes
1 answer

Boyer-Moore-Horspool Algorithm for All Matches (Find Byte array inside Byte array)

Here is my implementation of BMH algorithm (it works like a charm): public static Int64 IndexOf(this Byte[] value, Byte[] pattern) { if (value == null) throw new ArgumentNullException("value"); if (pattern == null) throw new…
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
8
votes
1 answer

std::search on single-pass range

I'd like to read from a std::istream until a certain sequence of characters is found, i.e., I'd like to implement the following interface: void read_until (std::istream &is, std::string_view needle); Using std::istreambuf_iterator, I believe this…
levzettelin
  • 2,600
  • 19
  • 32
8
votes
3 answers

What are the shift rules for Boyer–Moore string search algorithm?

I have been trying to understand shift rules in Boyer–Moore string search algorithm but haven't understood them. I read here on wikipedia but that is too complex ! It will be of great help if someone lists the rule in a simple manner.
saplingPro
  • 20,769
  • 53
  • 137
  • 195
5
votes
3 answers

Faster way to search for a string than the boyer moore algorithm?

Is there any faster way to search for a string in a file?
Levi H
  • 3,426
  • 7
  • 30
  • 43
5
votes
1 answer

Understanding Boyer-Moore string search algorithm's "Good Suffix Shift"-Table

Please help me to understand Boyer-Moore string search algorithm's "Good Suffix Shift"-Table. What has happened when i==3? There is no sub-string "_MAN" in the pattern. So the shift value should be 8 (as it was when i==1). Why is it 6?
user366312
  • 16,949
  • 65
  • 235
  • 452
5
votes
1 answer

Boyer and Moore algorithm, shift table calculation

I failed the whole evening to calculate a simple shift table for the search term "anabanana" for use in the Boyer and Moore pattern matching algorithm. I found the following example without any explanations: Can anybody help me understand and…
J-H
  • 1,795
  • 6
  • 22
  • 41
4
votes
0 answers

Will boyer moore maximum vote algorithm fail for certain cases?

Consider the following array with elements: 0 5 1 5 2 5 The algorithm does not return 5 as the majority element, but at the end of the first pass considers 2 as the majority element with a count of 0. Here is the pseudo code: num1 = array[0],…
truth_seeker
  • 345
  • 4
  • 14
4
votes
2 answers

StringUtils.contains of Apache and Boyer–Moore string search algorithm

To search for s in S (size(S) >= size(s) and return a true/false value), it's better for performance to use StringUtils.contains() of Apache or use Boyer-Moore algorithm implemented and tested well by someone I found? Thanks
xuongrong
  • 73
  • 1
  • 7
4
votes
0 answers

Implementation of Boyer Moore Horsepool algorithm with wildcards

I want to implement a generalization of the Boyer Moore Horspool algorithm that takes care of wildcards (match any letter in the word). This means that the pattern h _ _ s e would be found two times in this text: horsehouse. I need help to implement…
user265767
  • 559
  • 3
  • 12
  • 27
1
2 3 4 5 6