String matching

From Algowiki
Revision as of 19:30, 1 October 2014 by Cuozzo (talk | contribs) (→‎Known algorithms)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Input

Two non-empty sequences, [math]\displaystyle{ S }[/math] and [math]\displaystyle{ T }[/math]. Let [math]\displaystyle{ n(S),n(T) \in \mathbb{N} }[/math] denote the lengths of [math]\displaystyle{ S }[/math] and [math]\displaystyle{ T }[/math], respectively.

Output

A sorted sequences [math]\displaystyle{ P }[/math] of positions of [math]\displaystyle{ S }[/math], that is, [math]\displaystyle{ P[i] \in \{ 1,...,n(S)\} }[/math] for all positions of [math]\displaystyle{ P }[/math]. More specifically, [math]\displaystyle{ P }[/math] contains all positions [math]\displaystyle{ m }[/math] of [math]\displaystyle{ S }[/math] such that [math]\displaystyle{ S[m+j-1]=T[j] }[/math] for all [math]\displaystyle{ j \in \{ 1,...,n(T)\} }[/math]. Such a subsequence [math]\displaystyle{ (S[m],...,S[m+n(T)-1]) }[/math] is called an occurrence of [math]\displaystyle{ T }[/math] in [math]\displaystyle{ S }[/math].

Objective

N/A

Complexity

Known algorithms

Simple string matching algorithm

String matching based on finite automaton

Remark

Note that occurrences of [math]\displaystyle{ T }[/math] in [math]\displaystyle{ S }[/math] may overlap (otherwise, the string matching problem would be trivially solvable in linear time).