Implements the Knuth-Morris-Pratt (KMP) algorithm to efficiently find the first occurrence of a pattern in a given text. Uses the Longest Prefix Suffix (LPS) array to minimize unnecessary comparisons, resulting in a time complexity of O(n + m).
kmpSearch("abxabcabcaby", "abcaby") returns 6 since the pattern "abcaby" starts at index 6.
Adding more code file required for #219
Implements the Knuth-Morris-Pratt (KMP) algorithm to efficiently find the first occurrence of a pattern in a given text. Uses the Longest Prefix Suffix (LPS) array to minimize unnecessary comparisons, resulting in a time complexity of O(n + m).
kmpSearch("abxabcabcaby", "abcaby")
returns 6 since the pattern"abcaby"
starts at index 6.