Implement KMP algorithm for substring searching.