Definition
String Matching Problem
Algorithms
Brute-force Algorithm
Definition
Link to originalBrute-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.