Complexity of Sequential Pattern Matching Algorithms

Mireille Régnier, Wojciech SzpankowskiRANDOM 1998

TL;DR

This paper rigorously proves the existence of a "linearity constant" for sequential pattern matching algorithms, like Morris-Pratt, under general probabilistic models. This confirms that these algorithms' performance scales linearly with text size, even in the worst-case and average-case scenarios, providing a theoretical foundation for their practical efficiency.

What Problem Does This Paper Address?

String matching, the task of finding occurrences of a pattern within a larger text, is a fundamental problem in computer science. Algorithms like Knuth-Morris-Pratt (KMP) and its variants are known to be efficient, typically performing in time proportional to the length of the text (linear time). For decades, researchers have sought to establish tight bounds on this linear performance, specifically proving the existence of a constant factor that governs this relationship – the "linearity constant." While upper bounds were known, proving the existence of this constant, especially for general cases beyond simple models, remained an open challenge. This paper tackles this by formally defining a class of "sequential algorithms" (including KMP and its relatives) and proving the existence of this linearity constant for both worst-case and average-case scenarios under broad probabilistic assumptions.

Methods

The core of the paper's methodology lies in leveraging the Subadditive Ergodic Theorem. The authors first formally define "sequential algorithms," which are characterized by scanning the text from left to right and having certain properties related to how they handle mismatches and advance their search. A key concept introduced is "unavoidable alignment positions," which are positions in the text where the algorithm is guaranteed to perform a comparison, regardless of the specific text.

The proof strategy involves:

  1. Defining Sequential Algorithms: A formal definition is provided, encompassing algorithms like naive search and Morris-Pratt variants, focusing on their left-to-right scanning and specific mismatch handling.
  2. Introducing Unavoidable Positions: This structural property is crucial. The existence of these positions helps establish the subadditivity of the algorithm's complexity.
  3. Applying Subadditive Ergodic Theorem: The paper shows that the complexity function of these sequential algorithms, under certain probabilistic models (stationary and ergodic text/pattern), satisfies the conditions of the Subadditive Ergodic Theorem (or its almost subadditive variant). This theorem then guarantees the existence of the linearity constant.
  4. Worst-Case and Average-Case Analysis: The proofs cover both deterministic (worst-case) and probabilistic (average-case) models, demonstrating the robustness of the results.

Datasets

Not discussed in the paper. The analysis is theoretical and relies on probabilistic models of text and pattern generation rather than specific datasets.

Key Insights and Ideas

  • Theoretical Guarantee for Efficiency: The paper provides a rigorous mathematical proof that sequential pattern matching algorithms (like KMP) are indeed linearly bounded in the worst and average cases, confirming decades of empirical observation and intuition.
  • The Power of "Unavoidable Positions": The concept of unavoidable alignment positions is a novel structural property that is shown to be key to proving the subadditivity of the algorithm's complexity. This property is highlighted as potentially unique to Morris-Pratt-like algorithms.
  • General Probabilistic Models: The results hold under general assumptions of stationarity and ergodicity for text and pattern sequences, making them applicable to a wide range of real-world scenarios beyond simple random models.
  • Distinction from Boyer-Moore: The paper explicitly points out that the Boyer-Moore algorithm, while also efficient, does not possess the "unavoidable positions" property, suggesting that the techniques used here might not directly apply to proving its linearity.

Key Results

The paper establishes the following main results for $l$-convergent sequential string matching algorithms:

  • Worst-Case Complexity: Under a deterministic model, the complexity $c(t, p)$ satisfies $\lim_{n \to \infty} \frac{\max_t c(t, p)}{n} = \alpha(p)$, where $\alpha(p) \ge 1$ is a constant dependent on the pattern $p$.
  • Average-Case Complexity (Semi-Random Model): Under a semi-random model (stationary and ergodic text), the expected complexity $E[c_n]$ satisfies $\lim_{n \to \infty} \frac{E[c_n]}{n} = \alpha(p)$, where $\alpha(p) \ge 1$ is a constant.
  • Average-Case Complexity (Stationary Model): Under a stationary model (both text and pattern are stationary and ergodic), the complexity $C_n$ converges almost surely to $\alpha(p)$, i.e., $\lim_{n \to \infty} \frac{C_n}{n} = \alpha(p)$ (a.s.).

These results confirm that the complexity is indeed linear, with a constant factor $\alpha(p)$.

Limitations and Future Work

  • Boyer-Moore Algorithm: The paper notes that the techniques used (subadditivity and unavoidability) do not directly apply to proving the linearity of Boyer-Moore algorithms, as they lack the "unavoidable positions" property. The authors suggest that renewal theory might be a more suitable approach for analyzing Boyer-Moore.
  • "On-line" Algorithms: While the definition of semi-sequentiality is close to existing "on-line" algorithms, the paper doesn't fully explore the implications for all such algorithms, particularly those that might not satisfy condition (2) of sequentiality.
  • Future Work: The authors plan to investigate renewal theory for Boyer-Moore algorithms in a future paper. They also suggest that extending the approach to other classes of algorithms is a possibility.

Summary updated

BibTeX
@inproceedings{regnier1998complexity,
  author = {Mireille Régnier and Wojciech Szpankowski},
  title = {{Complexity of Sequential Pattern Matching Algorithms}},
  booktitle = {RANDOM},
  year = {1998},
  doi = {10.1007/3-540-49543-6\_16},
}

Loading related content...

Figure