Lably
Skip to content

Boyer–Moore string-search algorithm

String searching algorithm

  • 10 min read
  • 7 chapters

Related on Lably

Through Computer science, Preprocessor and String (computer science)

The algorithm preprocesses the string being searched for (the pattern), but not the string being searched in (the text). It is thus well-suited for applications in which the pattern is much shorter than the text or where it persists across multiple searches. The Boyer–Moore algorithm uses information gathered during the preprocess step to skip sections of the text, resulting in a lower constant factor than many other string search algorithms. In general, the algorithm runs faster as the pattern length increases. The key features of the algorithm are to match on the tail of the pattern rather than the head, and to skip along the text in jumps of multiple characters rather than searching every single character in the text.

Definitions

  • T denotes the input text to be searched. Its length is n.
  • P denotes the string to be searched for, called the pattern. Its length is m.
  • S[i] denotes the character at index i of string S, counting from 1.
  • S[i..j] denotes the substring of string S starting at index i and ending at j, inclusive.
  • A prefix of S is a substring S[1..i] for some i in range [1, l], where l is the length of S.
  • A suffix of S is a substring S[i..l] for some i in range [1, l], where l is the length of S.
  • An alignment of P to T is an index k in T such that the last character of P is aligned with index k of T.
  • A match or occurrence of P occurs at an alignment k if P is equivalent to T[(k-m+1)..k].

Sign in to keep reading

6 more chapters are free with a Lably account.

More in Computing and communication