FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/String-searching_algorithm

String-searching algorithm

Contents
        Algorithms using a finite set of patterns
        Algorithms using an infinite number of patterns
    Classification by the use of preprocessing programs
    Classification by matching strategies
    Real-time string matching
External links

A string-searching algorithm, sometimes called string-matching algorithm, is an algorithm that searches a body of text for portions that match by pattern.

A basic example of string searching is when the pattern and the searched text are arrays of elements of an alphabet (finite set) Σ. Σ may be a human language alphabet, for example, the letters A through Z and other applications may use a binary alphabet (Σ = {0,1}) or a DNA alphabet (Σ = {A,C,G,T}) in bioinformatics.

In practice, the method of feasible string-search algorithm may be affected by the string encoding. In particular, if a variable-width encoding is in use, then it may be slower to find the Nth character, perhaps requiring time proportional to N. This may significantly slow some search algorithms. One of many possible solutions is to search for the sequence of code units instead, but doing so may produce false matches unless the encoding is specifically designed to avoid it.Θ(n) time, and all

  1. ↑ Asymptotic times are expressed using O, Ω, and Θ notation.
  2. ↑ Used to implement the memmem and strstr search functions in the glibc and musl C standard libraries.
  3. ↑ Can be extended to handle approximate string matching and (potentially-infinite) sets of patterns represented as regular languages.

The Boyer–Moore string-search algorithm has been the standard benchmark for the practical string-search literature.

Algorithms using a finite set of patterns

edit

In the following compilation, M is the length of the longest pattern, m their total length, n the length of the searchable text, o the number of occurrences.

Algorithm Extension of Preprocessing time Matching time Space
Aho–Corasick Knuth–Morris–Pratt Θ(m) Θ(n + o) Θ(m)
Commentz-Walter Boyer-Moore Θ(m) Θ(M * n) worst case
sublinear in average
Θ(m)
Set-BOM Backward Oracle Matching

Algorithms using an infinite number of patterns

edit

Naturally, the patterns can not be enumerated finitely in this case. They are represented usually by a regular grammar or regular expression.

Classification by the use of preprocessing programs

edit

Other classification approaches are possible. One of the most common uses preprocessing as main criteria.

Classes of string searching algorithms
Text not preprocessed Text preprocessed
Patterns not preprocessed Elementary algorithms Index methods
Patterns preprocessed Constructed search engines Signature methods

Classification by matching strategies

edit

Another one classifies the algorithms by their matching strategy:

Real-time string matching

edit

In real-time string matching, one requires the matcher to output a response after reading each character of the text, that indicates whether this is the last character of a match. The response has to be given within constant time. The requirement regarding preprocessing vary: O(m) preprocessing may be allowed after the pattern is read (but before the reading of the text), or a stricter requirement may be posed according to which the matcher has to also pause for at most a constant time after reading any character of the pattern (including the last). For the more lenient version, if one does not mind that the preprocessing time and memory requirement dependend on the size of the alphabet, a real-time solution is provided by automaton matching. Zvi Galil developed a method to turn certain algorithms into real-time algorithms, and applied it to produce a variant of the KMP matcher that runs in real time under the strict requirement.

String searching with don't caresedit

In this version of the string searching problem, there is a special symbol, ø (read: don't care), which can match any other symbol (including another ø). Don't care symbols can appear either in the pattern or in the text. In 2002, an algorithm for this problem that runs in

  1. ↑ Stephen, Graham A. (1994-10-17). String Searching Algorithms. World Scientific. ISBN 978-981-4501-86-6.
  2. ↑ Crochemore, Maxime; Perrin, Dominique (1 July 1991). "Two-way string-matching" (PDF). Journal of the ACM. 38 (3): 650–674. doi:10.1145/116825.116845. S2CID 15055316. Archived (PDF) from the original on 24 November 2021. Retrieved 5 April 2019.
  3. ↑ Navarro, Gonzalo; Raffinot, Mathieu (1998). "A bit-parallel approach to suffix automata: Fast extended string matching" (PDF). Combinatorial Pattern Matching. Lecture Notes in Computer Science. Vol. 1448. Springer Berlin Heidelberg. pp. 14–33. doi:10.1007/bfb0030778. ISBN 978-3-540-64739-3. Archived (PDF) from the original on 2019-01-05. Retrieved 2019-11-22.
  4. ↑ Commentz-Walter, Beate (1979). A String Matching Algorithm Fast on the Average (PDF). International Colloquium on Automata, Languages and Programming. LNCS. Vol. 71. Graz, Austria: Springer. pp. 118–132. doi:10.1007/3-540-09510-1_10. ISBN 3-540-09510-1. Archived from the original (PDF) on 2017-10-10.
  5. ↑ Melichar, Borivoj, Jan Holub, and J. Polcar. Text Searching Algorithms. Volume I: Forward String Matching. Vol. 1. 2 vols., 2005. http://stringology.org/athens/TextSearchingAlgorithms/ Archived 2016-03-04 at the Wayback Machine.
  6. ↑ Galil, Zvi (1981). "String matching in real time". Journal of the ACM. 28 (1): 134–149. doi:10.1145/322234.322244.
  7. ↑ ISBN 0-262-03293-7. Chapter 32: String Matching, pp. 985–1013.
  8. External links

    edit
    Wikimedia Commons has media related to String-searching algorithm.
    Strings
    String metric
    String-searching algorithm
    Multiple string searching
    Regular expression
    Sequence alignment
    Data structure
    Other

    View original on Wikipedia | Back | FazBrowse Home