Re: Complexity of :matches ?

Philip Guenther <guenther+mtafilters@sendmail.com> Tue, 12 July 2005 11:36 UTC

Received: from above.proper.com (localhost.vpnc.org [127.0.0.1]) by above.proper.com (8.12.11/8.12.9) with ESMTP id j6CBaqX5083915; Tue, 12 Jul 2005 04:36:52 -0700 (PDT) (envelope-from owner-ietf-mta-filters@mail.imc.org)
Received: (from majordom@localhost) by above.proper.com (8.12.11/8.12.9/Submit) id j6CBaq7k083914; Tue, 12 Jul 2005 04:36:52 -0700 (PDT)
X-Authentication-Warning: above.proper.com: majordom set sender to owner-ietf-mta-filters@mail.imc.org using -f
Received: from foon.sendmail.com (tls.sendmail.com [209.246.26.40]) by above.proper.com (8.12.11/8.12.9) with ESMTP id j6CBaqH1083906 for <ietf-mta-filters@imc.org>; Tue, 12 Jul 2005 04:36:52 -0700 (PDT) (envelope-from guenther@sendmail.com)
Received: from lab.smi.sendmail.com ([10.210.100.93]) by foon.sendmail.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id j6CBapeP024336 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for <ietf-mta-filters@imc.org>; Tue, 12 Jul 2005 04:36:51 -0700
X-DomainKeys: Sendmail DomainKeys Filter v0.2.7 foon.sendmail.com j6CBapeP024336
DomainKey-Signature: a=rsa-sha1; s=tls; d=sendmail.com; c=nofws; q=dns; b=raMoG4lUW+fS0LbUCSTPWEeRUVeIL3bSXiN0V9Mp6E0xjhCfTRVsUIhaijJ7UqlKr B1UNa4ZvHwW807+zRS816sWYHM1BYlBBW6WuJr/4rU2o943q3n8rGKwOw1GKYOgdfnS +PeV2pQyEXFf6Hr8kAJnpeFj2Leuf/XyozVQBHQ=
Received: from lab.smi.sendmail.com (localhost [127.0.0.1]) by lab.smi.sendmail.com (8.12.11/8.12.11) with ESMTP id j6CBapWi042099 for <ietf-mta-filters@imc.org>; Tue, 12 Jul 2005 04:36:51 -0700 (PDT) (envelope-from guenther@lab.smi.sendmail.com)
Message-Id: <200507121136.j6CBapWi042099@lab.smi.sendmail.com>
From: Philip Guenther <guenther+mtafilters@sendmail.com>
To: ietf-mta-filters@imc.org
Subject: Re: Complexity of :matches ?
In-reply-to: <200507121052.j6CAq1rH038682@lab.smi.sendmail.com>
References: <E1DsGVb-0003gO-Fg@nostromo.freenet-ag.de> <200507121052.j6CAq1rH038682@lab.smi.sendmail.com>
Date: Tue, 12 Jul 2005 04:36:51 -0700
Sender: owner-ietf-mta-filters@mail.imc.org
Precedence: bulk
List-Archive: <http://www.imc.org/ietf-mta-filters/mail-archive/>
List-ID: <ietf-mta-filters.imc.org>
List-Unsubscribe: <mailto:ietf-mta-filters-request@imc.org?body=unsubscribe>

I, Philip Guenther <guenther+mtafilters@sendmail.com> wrote:
...
>For an NFA, the setup is O(N) in time and space and matching is O(N*M).
>
>For a non-lazy DFA, the matching is O(M), but the worst-case setup is
>O(2^N).
...

I should note that the dragon book's statements, as I tried to
summarize above, are only true of the original, truly regular
"regular expressions" and not the extended or 'irregular' regular
expressions seen in most tools.

In particular, counted repetitions ({n,m}) have to be expanded when
figuring the 'N' of the size of the regexp, while back-references
(\digit) are, IIRC, worst-case exponential to match.  If you're
capturing matches then the POSIX matching rules apparently are
worst-case exponential on the number of characters in the regexp,
or something like that.


Philip Guenther