タグ

NP-hardに関するsmoking186のブックマーク (2)

  • Perl Regular Expression Matching is NP-Hard

    Matching ordinary regular expresions can be done in polynomial time, proportional to MN, where M is the length of the regular expression and N is the length of the string to be matched. The usual method for this is: Parse the regular expression and construct an equivalent finite automaton (FA), which will have O(M) states; then simulate the action of the FA on the input, which takes O(MN) time. My

  • 後方参照のある正規表現の能力 - まめめも

    定期的に出てくる話題ですが、プログラミングで出てくる正規表現は正規表現ではないので、素数判定ができます。正確には、文字列の長さが素数かどうかを判定できます。2 文字以上のマッチが 2 回以上出現するかどうかを見ます。後方参照がポイント。 p (2..30).select{|x| !("X" * x)[/^(..+)\1+$/] } #=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] ところで、{ a^n | n は素数 } は文脈依存言語のはずなので、後方参照のある正規表現は線形拘束オートマトン以上の表現力を持つことになるのでしょうか。でも、文脈自由文法である { a^nb^n | n は自然数 } や括弧の対応は書けなさそうです。ちょっと調べてみても、後方参照のある正規表現の能力はよくわかりませんでした。 とりあえずPerl の正規表現マッチングで 3-CN

    後方参照のある正規表現の能力 - まめめも
    smoking186
    smoking186 2007/08/10
    NP-hardって
  • 1