NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

On the shift-table in Boyer-Moore’s String Matching Algorithm

Yan WangInternational Journal of Digital Content Technology and its Applications 2009

TL;DR

This paper introduces a new, more intuitive method for computing the "shift table" in the Boyer-Moore string matching algorithm. By defining and utilizing an auxiliary array called suffixLength, the authors provide a conceptually simpler and easier-to-implement approach that maintains the algorithm's optimal O(m) time and space complexity.

What Problem Does This Paper Address?

The Boyer-Moore string matching algorithm is renowned for its efficiency, often outperforming other algorithms in practice. However, its practical adoption has been somewhat limited by the perceived complexity of its preprocessing steps, particularly the computation of the "shift table." This table is crucial for determining how far to shift the pattern across the text after a mismatch, and existing methods for its calculation are considered by many to be unintuitive and difficult to grasp. This paper aims to demystify this process by offering a more straightforward and conceptually clear alternative.

Methods

The core contribution of this paper is the introduction of a new auxiliary array, suffixLength. This array is defined based on the longest substring ending at a given position in the pattern that also matches a suffix of the pattern. The authors then establish theoretical properties of suffixLength and present an algorithm to compute it in linear time, O(m), where m is the length of the pattern.

Crucially, the paper demonstrates how the shift table, which is the more complex of the two precomputed tables in Boyer-Moore, can be derived directly from suffixLength. This derivation is presented through a series of theorems that link the values in suffixLength to the necessary shift amounts based on different mismatch scenarios. The paper provides pseudocode for both computing suffixLength and then using it to compute the shift table, all within O(m) time complexity.

Datasets

Not discussed in the paper. The paper focuses on algorithmic development and theoretical properties rather than empirical evaluation on specific datasets.

Key Insights and Ideas

  • suffixLength as a simpler building block: The paper argues that suffixLength is conceptually simpler than the intermediate array f used in some existing shift table computation algorithms. This simplicity makes it easier to understand and implement.
  • Direct link between suffixLength and shift: The core insight is that the complex shift logic of the Boyer-Moore algorithm can be directly translated into calculations based on suffixLength, providing a more transparent derivation.
  • O(m) computation for shift table: By leveraging suffixLength, the paper achieves the optimal O(m) time complexity for computing the shift table, preserving the overall efficiency of the Boyer-Moore algorithm.
  • Demystifying Boyer-Moore: The paper's primary goal is to make the Boyer-Moore algorithm more accessible by simplifying its most challenging preprocessing step.

Key Results

The paper presents an algorithm to compute the suffixLength array in O(m) time and then uses this array to compute the shift table in O(m) time. This means the entire preprocessing phase for the Boyer-Moore algorithm can be performed in linear time with respect to the pattern length, maintaining the algorithm's high performance. The paper provides theoretical proofs for its theorems, establishing the correctness of its approach.

Limitations and Future Work

The paper primarily focuses on the theoretical development of a new method for computing the shift table. While it claims the method is more intuitive and easier to implement, it does not provide empirical comparisons or benchmarks against existing implementations. Future work could involve implementing and evaluating this new approach to quantify its practical benefits in terms of ease of use and potential performance gains in real-world scenarios. The authors suggest that this simplified approach could encourage wider adoption of the Boyer-Moore algorithm.

Summary updated

BibTeX
@article{wang2009shift,
  author = {Yan Wang},
  title = {{On the shift-table in Boyer-Moore’s String Matching Algorithm}},
  journal = {International Journal of Digital Content Technology and its Applications},
  year = {2009},
  doi = {10.4156/jdcta.vol3.issue4.1},
}
Figure