A look at several substring search algorithms
In software programming, it is very common to find a situation where we need to search for the occurrences of a specific pattern of characters in a bigger text. We are going to see some types of search algorithm that will help us with this task.
In order to explain them, first we are going to specify some assumptions:
- The text is defined as an array
T[1..n]
, with length n, which contains chars. - The pattern that we are searching for is defined as an array
P[1..m]
, with length m and m <= n. - Where the pattern P exists in T, we call it shift s in T. In other words, the pattern P occurs in the s+1 position of the T array. So, this also implies that [1 < s < m-n] and also T[s+1 .. s+m] = P[1 .. m].
Look at the ...
Get Swift Data Structure and Algorithms now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.