A string-searching algorithm locates occurrences of a pattern in a text, typically requiring a contiguous substring match. For text ababa and pattern aba, zero-based matches start at zero and two; overlaps count unless excluded by the specification. The direct algorithm compares the pattern at each start and can require character comparisons. The Knuth-Morris-Pratt algorithm reuses prefix information for linear total scanning work. State the alphabet, case handling and empty-pattern convention: matching bytes, Unicode code points and user-perceived characters can describe different tasks.
A longest repeated substring is a maximum-length contiguous string occurring at two distinct starting positions in a text. The occurrences may overlap unless a nonoverlap constraint is explicitly imposed. It can be found by comparing all pairs of suffixes, or by taking the maximum longest-common-prefix length of adjacent entries of a suffix array. The latter characterization concerns correctness; the time needed to build the suffix array depends on the construction algorithm.
An FM-index is a compressed text index supporting backward search through the Burrows-Wheeler transform and occurrence counts. Character rank queries locate a matching interval; sampled suffix array positions then allow the actual text positions to be recovered. Query length, number of matches and the chosen sampling density control different parts of the search cost.[ref]
Backward search finds a query's matching interval in a suffix array by processing the query from right to left. With inclusive one-based interval , prepending changes it to . An empty interval means no match. This works through the occurrence-order property of the last-to-first mapping.[ref]
In a sorted cyclic rotation matrix, the last-to-first mapping sends the th occurrence of a character in the last column to its th occurrence in the first column. For one-based rows, , where counts smaller characters and counts in the first entries of the last column. It moves a rotation's start one character backwards cyclically. Equal characters retain the lexicographic order of their following sequences, which proves the occurrence-order rule.[ref]
The Burrows-Wheeler transform appends a unique smallest terminator to a string, sorts its cyclic rotations in lexicographic order, and records the last column. It is reversible because the first and last columns contain the same characters and the last-to-first mapping preserves the occurrence order of each character. The resulting letter arrangement supports both compression and backward search.[ref]
A transition to a shorter suffix match after an attempted extension fails. In a Knuth-Morris-Pratt automaton, the prefix function determines the next shorter matching prefix.
The Knuth-Morris-Pratt algorithm searches for a pattern using its proper prefix-suffix overlaps. After matching characters, a mismatch replaces by the length of the longest proper border of a string for that matched prefix, repeating until the next character can extend it or . The text index never moves backward. Precomputing prefix failure links takes time; during scanning each increase in can pay for a later decrease, giving total character work and auxiliary storage. A dense Knuth-Morris-Pratt automaton is a related implementation with alphabet-dependent preprocessing and storage.[ref]
A Knuth-Morris-Pratt automaton records how much of a fixed pattern matches the suffix of the text seen so far. State means the longest such prefix has length ; reading a symbol moves to the longest compatible prefix state. Reaching state reports a full length- match. For pattern aba, state two records suffix ab; reading a completes the match, while reading b falls back to state zero. A dense table for an alphabet of size uses preprocessing and storage, then constant work per text symbol.[ref]
A border of a string is a string that is both a prefix and a suffix. A proper border is shorter than the whole string; the empty string is often included. The string ababa has proper nonempty borders a and aba. A border of length in a length- string corresponds to an overlap displacement . The Knuth-Morris-Pratt algorithm uses a chain of such borders to decide how much of a partial match survives a mismatch, avoiding comparison of characters already known to agree.
A proper border of a string is a string prefix that is also a string suffix and is shorter than the complete string. With zero-based lengths, its length satisfies for a length- string, if the empty string is allowed. Specify that convention when counting borders.
For ababa, the nonempty proper borders are a and aba; the complete ababa is a border of a string but not a proper one. A proper border of length allows two copies of the string to overlap with displacement . The border aba therefore explains the shift of two between overlapping occurrences of ababa in abababa.
The prefix function stores the longest proper-border length of each prefix. For ababa, following these lengths gives , listing successively shorter candidate overlaps. The Knuth-Morris-Pratt algorithm uses this chain after a mismatch, retaining a suffix already known to match rather than comparing the whole pattern again.
For a string , the value is the length of the longest proper prefix of that is also its suffix. Repeatedly following these lengths lists all proper borders of a string; this is the failure-link information used by the Knuth-Morris-Pratt algorithm.

Articles by others on the same topic (0)

There are currently no matching articles.