Skip to main content
QUICK REVIEW

[Paper Review] Speeding Up String Matching by Weak Factor Recognition

Domenico Cantone, Simone Faro|arXiv (Cornell University)|Jul 3, 2017
Algorithms and Data CompressionComputer Science16 references4 citations
TL;DR

This paper presents the Wfr algorithm, a fast string matching method that uses weak factor recognition via hashing to efficiently locate all occurrences of a pattern in a text. Despite a quadratic worst-case time complexity, it achieves sublinear average performance and outperforms existing algorithms—especially on small alphabets and long patterns—by up to 28% in speed gains due to longer, more effective shifts and optimized hashing.

ABSTRACT

String matching is the problem of finding all the substrings of a text which match a given pattern. It is one of the most investigated problems in computer science, mainly due to its very diverse applications in several fields. Recently, much research in the string matching field has focused on the efficiency and flexibility of the searching procedure and quite effective techniques have been proposed for speeding up the existing solutions. In this context, algorithms based on factors recognition are among the best solutions. In this paper, we present a simple and very efficient algorithm for string matching based on a weak factor recognition and hashing. Our algorithm has a quadratic worst-case running time. However, despite its quadratic complexity, experimental results show that our algorithm obtains in most cases the best running times when compared, under various conditions, against the most effective algorithms present in literature. In the case of small alphabets and long patterns, the gain in running times reaches 28%. This makes our proposed algorithm one of the most flexible solutions in practical cases.

Motivation & Objective

  • Address the need for faster, practical string matching algorithms in real-world applications despite extensive prior research.
  • Improve upon existing factor-recognition-based algorithms by introducing a weaker, yet more efficient, recognition model.
  • Design a simple, fast, and flexible solution that maintains high performance across diverse input conditions.
  • Demonstrate that weak factor recognition with hashing can yield competitive or superior performance compared to strong factor recognition methods.
  • Evaluate the algorithm’s efficiency empirically across various pattern lengths, alphabets, and real-world datasets.

Proposed method

  • Propose a weak factor recognition approach using a hash function to identify potential pattern factors in the text.
  • Use a rolling hash to efficiently compute hash values of substrings during the search phase.
  • Implement a shift mechanism that skips over non-matching regions based on hash comparisons, reducing unnecessary character comparisons.
  • Introduce a variant, Wfr_q, with unchained-loop optimization to further improve performance in the search phase.
  • Leverage the fact that the hash function accepts all true factors of the pattern and possibly some false positives, relying on post-checking for correctness.
  • Compare the algorithm’s performance against state-of-the-art algorithms using standardized benchmarks on real sequences (DNA, protein, natural language).

Experimental results

Research questions

  • RQ1Can a weak factor recognition approach with hashing outperform strong factor recognition methods in practical string matching?
  • RQ2How does the Wfr algorithm perform relative to existing algorithms like BNDM, BOM, and BSDM across varying pattern lengths and alphabet sizes?
  • RQ3What is the impact of using a single hash function versus multiple functions on false positives and overall efficiency?
  • RQ4Does the Wfr algorithm achieve sublinear average-case performance despite its worst-case O(nm) complexity?
  • RQ5In what input regimes (e.g., small vs. large alphabets, long vs. short patterns) does the Wfr algorithm show the greatest performance advantage?

Key findings

  • The Wfr algorithm achieves up to a 28% performance gain over existing algorithms on long patterns with small alphabets, particularly in DNA and protein sequences.
  • The Wfr_q variant, with unchained-loop optimization, becomes the fastest solution for moderate to long patterns (m ≥ 32), outperforming BSDM_q and EBOM in many cases.
  • On small alphabets, the performance gain reaches up to 25%, while on large alphabets, the gain is still significant at up to 14%.
  • The algorithm shows sublinear average-case behavior in practice, despite having a worst-case O(nm) time complexity.
  • The Wfr algorithm performs better than BSDM_q for m ≥ 256 due to longer average shifts, which reduce the number of comparisons.
  • The use of a single, well-designed hash function enables fast factor recognition with minimal overhead, making the algorithm both simple and highly effective.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.