FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Two-way_string-matching_algorithm

Two-way string-matching algorithm

"},"class":{"wt":"[[String-searching algorithm]]"},"image":{"wt":""},"caption":{"wt":""},"data":{"wt":"Any [[String (computer science)|string]] with an ordered alphabet"},"time":{"wt":"O(n)"},"best-time":{"wt":"O(n)"},"average-time":{"wt":""},"space":{"wt":"O(1)"}},"i":0}}]}'>
ClassString-searching algorithm
Data structureAny string with an ordered alphabet
Worst-case performanceO(n)
Best-case performanceO(n)
Worst-case space complexityO(1)

In computer science, the two-way string-matching algorithm (or Crochemore-Perrin string-matching algorithm) is a string-searching algorithm, discovered by Maxime Crochemore and Dominique Perrin in 1991. It searches for copies of a "needle" of length m in a "haystack" of length n. After preprocessing the needle in time O(m), the actual search takes time O(n) linear in the length of the haystack.

The two-way algorithm can be viewed as a combination of the forward-going Knuth–Morris–Pratt algorithm (KMP) and the backward-running Boyer–Moore string-search algorithm (BM). Like those two, the two-way algorithm preprocesses the needle to find partially repeating periods and computes “shifts” based on them, indicating what offset to “jump” to in the haystack when a given character is encountered.

Unlike BM and KMP, it uses only O(1) additional space to store information about those partial repeats (assuming the transdichotomous model, where an index of ⌈log2(m)⌉ bits is counted as a single word). The preprocessing computes the "period" of the needle, the minimum offset between two consecutive matches (a value between 1 and m), and a "critical factorization" of the needle into a prefix and suffix with particular properties, specified by the length of the prefix (also less than m).

The actual matching operation performs at most 2n − m comparisons.

Breslauer later published two improved variants performing fewer comparisons, at the cost of storing additional data about the preprocessed needle:

In other words, ⁠(u,v)⁠ is denoted as vu is guaranteed to exist and has the same length as 1≤r(u,v)≤len(x)⁠.

Finally, a critical factorization is a factorization x such that m in an ordered alphabet, it can be computed in Charras, Christian; Lecroq, Thierry (14 January 1997). "Two Way algorithm". Exact String Matching Algorithms. Institut Gaspard Monge.

  • ↑ "newlib/libc/string/memmem.c". Retrieved 23 November 2019.
  • 1 2 Adamczyk, Zbigniew; Rytter, Wojciech (May 2013). "A note on a simple computation of the maximal suffix of a string" (PDF). Journal of Discrete Algorithms. 20: 61–64. doi:10.1016/j.jda.2013.03.002.
  • Strings
    String metric
    String-searching algorithm
    Multiple string searching
    Regular expression
    Sequence alignment
    Data structure
    Other

    View original on Wikipedia | Back | FazBrowse Home