In KMP algorithm we preprocess the pattern to find the longest prefix which we used to skip characters while matching.
while in Z- algorithm we first make a new string
new_string = pattern + 'x' + string
where x = character that doesn't exist in both pattern and string
After making the new_string we preprocess the new_string to find longest prefix and if the lent of prefix is equal to pattern length then we found the pattern
Both have time complexity of O(m+n).
so what is the difference between these two algorithms and which one is best to use?