KMP and Z algorithms are well-known algorithms for finding strings,
KMP algorithm deals with finding patterns using the KMP reject function, which is defined as ( pat is a search pattern)
lps [i] = the longest valid prefix pat [0..i], which is also the suffix pat [0..i].
for example, for string "abcab" it will be [0, 0, 0, 1, 2]
where the function z is used as the algorithm Z , which is defined as:
Given a string S of length n, the Z-algorithm creates an array Z, where Z [i] is the length of the longest substring, starting with pat [i], which is also the prefix pat.
Now the question is, can we achieve function Z using the KMP algorithm? I am looking for several modifications in the lps array, which leads to the same results as the Z[i] array.
string algorithm search
Ninja420
source share