Algorithm for linear pattern matching?

后端 未结 7 1967
失恋的感觉
失恋的感觉 2021-02-03 15:49

I have a linear list of zeros and ones and I need to match multiple simple patterns and find the first occurrence. For example, I might need to find 0001101101,

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-03 16:30

    The key for Googling is "multi-pattern" string matching.

    Back in 1975, Aho and Corasick published a (linear-time) algorithm, which was used in the original version of fgrep. The algorithm subsequently got refined by many researchers. For example, Commentz-Walter (1979) combined Aho&Corasick with Boyer&Moore matching. Baeza-Yates (1989) combined AC with the Boyer-Moore-Horspool variant. Wu and Manber (1994) did similar work.

    An alternative to the AC line of multi-pattern matching algorithms is Rabin and Karp's algorithm.

    I suggest to start with reading the Aho-Corasick and Rabin-Karp Wikipedia pages and then decide whether that would make sense in your case. If so, maybe there already is an implementation for your language/runtime available.

提交回复
热议问题