logoalt Hacker News

xpontoday at 4:49 AM3 repliesview on HN

Modulo an exponential blowup! That’s like saying P is equivalent to NP.


Replies

tgvtoday at 6:49 AM

Depends on what you mean by that. You can convert every NFA into a DFA. That's a NP complete (IIRC), but running the DFA is O(n). Running the NFA without converting it is also NP complete. One isn't better than the other, but the costs vary for different expressions and usages.

show 1 reply
pkaltoday at 6:26 AM

No, because you can compute the optimal automaton (as in least number of states) that recognizes the same language: https://en.wikipedia.org/wiki/DFA_minimization

show 1 reply
frohtoday at 5:53 AM

The blow up is exponential for carefully crafted academical regular expressions.

im practice is a good idea to build a DFA from your regex, up front (re2) or lazily (ripgrep)