Skip to content

Faster Regular Expression Matching via Two-Dimensional Tabulation

Philip Bille, Inge Li Gørtz

cs.DS

Abstract

A regular expression specifies a set of strings formed by single characters combined with concatenation, union, and Kleene star operators. Given a regular expression RR and a string QQ, the classic regular expression matching problem is to decide whether QQ matches any string specified by RR. Let mm and nn be the lengths of RR and QQ, respectively. Our main result is a new algorithm that, given a parameter t≥mt \geq m, solves the problem in O(nm lg⁡lg⁡(t/m)lg⁡2(t/m)+t+n)O\left(\frac{nm\,\lg\lg(t/m)}{\lg^2(t/m)}+t+n\right) time and O(t)O(t) words of space. In particular, for any fixed 0<\eps<10<\eps<1, when m≤n1−\epsm\leq n^{1-\eps}, we solve the problem in O(nmlg⁡lg⁡n/lg⁡2n+m+n)O(nm \lg \lg n/\lg^2 n + m + n) time and O(n)O(n) space. Compared to the previous best result [Bille and Thorup, ICALP 2009], this improves the leading term by a factor lg⁡n/lg⁡lg⁡n\sqrt{\lg n}/\lg\lg n. The key new technique is a two-dimensional tabulation specialized to the regular expression.

Create a lesson