Lukas' Notes

Definition

String Matching Problem

Given a text string and a pattern string over an alphabet . The string matching problem asks for all indices such that occurs in starting at position , i.e. .

Input:
Output: all occurrences of in

Algorithms

Brute-force Algorithm

Definition

Brute-force Algorithm (String Matching)

Given a text and a pattern , the brute-force algorithm for the string matching problem tests every possible starting position. At each position, it compares pattern characters with text characters from left to right until a mismatch occurs or the whole pattern matches. It returns

After each test, the starting position advances by one, so overlapping occurrences are retained. If , there are no occurrences. The empty string occurs at all boundaries of the text.

Link to original