[Paper Review] New Algorithms for Regular Expression Matching
This paper presents new algorithms for regular expression matching that achieve improved time bounds using O(m) space by leveraging word-level parallelism in a unit-cost RAM model. The key contribution is a hierarchical decomposition of NFAs and efficient bitstring operations to simulate state sets in O(log m) time per step, resulting in sublinear time complexity for small to moderate regex sizes, especially when m ≤ √w or w > log²n.
In this paper we revisit the classical regular expression matching problem, namely, given a regular expression $R$ and a string $Q$, decide if $Q$ matches one of the strings specified by $R$. Let $m$ and $n$ be the length of $R$ and $Q$, respectively. On a standard unit-cost RAM with word length $w \geq \log n$, we show that the problem can be solved in $O(m)$ space with the following running times: \begin{equation*} \begin{cases} O(n\frac{m \log w}{w} + m \log w) & ext{if $m > w$} \\ O(n\log m + m\log m) & ext{if $\sqrt{w} < m \leq w$} \\ O(\min(n+ m^2, n\log m + m\log m)) & ext{if $m \leq \sqrt{w}$.} \end{cases} \end{equation*} This improves the best known time bound among algorithms using $O(m)$ space. Whenever $w \geq \log^2 n$ it improves all known time bounds regardless of how much space is used.
Motivation & Objective
- To improve the time complexity of regular expression matching while maintaining O(m) space usage.
- To overcome the limitations of existing NFA simulation and DFA construction methods, especially the exponential space cost of DFA-based approaches.
- To exploit word-level parallelism in a unit-cost RAM model to simulate NFAs more efficiently than traditional state-set methods.
- To eliminate the need for large DFA tables that cause cache misses in practice, offering a more cache-friendly alternative.
Proposed method
- Introduces a hierarchical decomposition of NFAs to enable efficient parallel simulation using bit-level operations.
- Employs bitstring representations of state sets and uses bitwise operations (AND, OR, shift, NOT) to simulate transitions in bulk.
- Uses a separator mapping technique to partition NFA states into intervals, enabling constant-time operations via precomputed bitmaps.
- Leverages word-level parallelism to simulate multiple NFA states simultaneously, reducing the simulation time from O(m) to O(log m) per step.
- Applies a simulation data structure with O(m log m) preprocessing time and O(log m) time per operation, enabling efficient state-set updates.
- Reduces large NFA simulations to smaller subproblems using recursive decomposition and bit-level aggregation.
Experimental results
Research questions
- RQ1Can regular expression matching be accelerated using word-level parallelism without constructing large DFAs?
- RQ2What is the best achievable time complexity for regular expression matching using only O(m) space?
- RQ3How can NFA state-set simulation be optimized to avoid the O(m) per-step cost of traditional methods?
- RQ4Can the exponential space blowup of DFA-based methods be avoided while retaining near-linear time performance?
- RQ5What role does word size w play in determining the performance of regular expression matching algorithms?
Key findings
- The algorithm achieves O(n·m·log w / w + m·log w) time when m > w, providing a significant speedup for large regexes.
- For √w < m ≤ w, the time bound is O(n·log m + m·log m), improving over Thompson’s O(n·m) for moderate regex sizes.
- When m ≤ √w, the time complexity is O(min(n + m², n·log m + m·log m)), achieving optimal O(n) time for very small regexes.
- The algorithm improves all known time bounds when w ≥ log²n, regardless of space usage, due to enhanced word-level parallelism.
- For m = O(log n), the algorithm achieves O(n·log log n) time and O(log n) space, avoiding the exponential space cost of DFA construction.
- The method avoids large lookup tables, reducing cache misses and offering practical advantages over previous DFA-based approaches.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.