Optimal Space and Time for Streaming Pattern Matching

Tung Mai, Anup B. Rao, Ryan A. Rossi, Saeed SeddighinarXiv 2021

Abstract

In this work, we study longest common substring, pattern matching, and wildcard pattern matching in the asymmetric streaming model. In this streaming model, we have random access to one string and streaming access to the other one. We present streaming algorithms with provable guarantees for these three fundamental problems. In particular, our algorithms for pattern matching improve the upper bound and beat the unconditional lower bounds on the memory of randomized and deterministic streaming algorithms. In addition to this, we present algorithms for wildcard pattern matching in the asymmetric streaming model that have optimal space and time.

Introduction

In the era of Big Data, processing strings that exceed memory capacity is a critical challenge. Standard streaming algorithms address this by processing data in a single pass with sublinear memory. However, for fundamental problems like Pattern Matching (finding pattern $P$ in text $T$), traditional deterministic streaming requires $\Omega(m)$ space, where $m$ is the pattern length.

This paper focuses on the asymmetric streaming model. In this scenario, one string (e.g., a large reference genome) is available via random access, while the other (e.g., incoming network traffic) arrives as a stream. The authors investigate whether these fundamental string operations can be performed with significantly less memory and time by leveraging this asymmetry.

Algorithmic Methods

The paper introduces several clever strategies to optimize performance:

  • Rolling Hashes for Pattern Matching: For Pattern Matching, the authors use a randomized hashing technique. They maintain pointers on the random-access string representing potential matches. As new characters arrive in the stream, they update the hash in $O(1)$ time and shift pointers to find valid matches.
  • Iterative Postfix Tracking for LCS: To find the Longest Common Substring (LCS), the algorithm maintains the largest substring of the random-access string that is also a postfix of the current stream. By updating this iteratively, they track the overall maximum length using only $O(1)$ space.
  • Sampling for Wildcards: Since the authors prove that exact Wildcard Pattern Matching (WPM) is impossible in sublinear space for streaming, they propose a non-streaming algorithm using sampling. By selecting characters at specific intervals, they reduce the problem to a series of smaller oracle calls, allowing a trade-off between space ($s$) and time ($n^2/s$).

Key Results

The most significant finding is that having random access to just one of the two strings fundamentally breaks the lower bounds of the standard streaming model. For Pattern Matching, the memory requirement drops from linear to constant ($O(1)$).

Summary of algorithmic results for asymmetric streaming problems, detailing runtime, space, and solution types.

As shown in the table above, the paper provides a suite of algorithms with provable guarantees. While exact LCS in $O(1)$ space takes quadratic time, the authors demonstrate that accepting a $(1-\epsilon)$ approximation allows for subquadratic runtimes, making the algorithm more practical for massive datasets.

Limitations and Future Work

While the results are groundbreaking, some open challenges remain. The $O(1)$ space algorithm for LCS is quadratic in time; finding an exact, subquadratic, $O(1)$ space algorithm is still an objective for future research. Additionally, the $O(1)$ space, linear-time Pattern Matching algorithm is randomized; the deterministic version currently requires quadratic time. Finally, the impossibility result for Wildcard Pattern Matching in the streaming model suggests that researchers must explore multi-pass algorithms or remain within the random-access model for that specific problem.

Summary updated

BibTeX
@misc{mai2021optimal,
  author = {Tung Mai and Anup B. Rao and Ryan A. Rossi and Saeed Seddighin},
  title = {{Optimal Space and Time for Streaming Pattern Matching}},
  year = {2021},
  eprint = {2107.04660},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2107.04660},
}
Figure