Math 2.0

Computer science Definition

String-searching algorithm

Builds on AlphabetStringAlgorithm

Definition

Let Σ\Sigma be a finite alphabet. Let P=p1⋯pmP = p_1 \cdots p_m and T=t1⋯tnT = t_1 \cdots t_n be strings over Σ\Sigma with 1≤m≤n1 \le m \le n; PP is the pattern and TT is the text. The pattern occurs at position ii of TT, where 1≤i≤n−m+11 \le i \le n - m + 1, if ti+j−1=pjt_{i + j - 1} = p_j for all j=1,…,mj = 1, \dots, m. A string-searching algorithm is an algorithm that, given PP and TT, outputs the set of all positions at which PP occurs in TT.

Remarks

Example: the naive algorithm checks, for each i=1,…,n−m+1i = 1, \dots, n - m + 1, the mm equalities ti+j−1=pjt_{i + j - 1} = p_j in turn. It outputs exactly the positions of occurrence, so it is a string-searching algorithm, and it uses O(nm)O(nm) comparisons. For T=abracadabraT = abracadabra and P=abraP = abra it outputs {1,8}\set{1, 8}.

Non-example: a procedure that stops and outputs the first position of an occurrence solves only the weaker problem of finding one occurrence, not all of them.

Many variants exist: searching for several patterns at once, as in the Aho–Corasick algorithm, or allowing a bounded number of mismatches.

Reading path

To understand this page from the ground up, read these 4 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Algorithm concept
  2. Alphabet concept
  3. String concept
  4. String-searching algorithm definition

Further reading

  1. Web https://en.wikipedia.org/wiki/String-searching_algorithm
About this page
TagR75EQC05SX
URIm2://R75EQC05SX
Kinddefinition
WritingW0 stub
MSC68W32, 68R15, 68W40
DefinesString-searching algorithm
UsesAlphabet, String, Algorithm
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.