Need clarification on the best time complexity & the worst time complexity of KMP algorithm. The thing that is confusing to me is the worst search time complexity of O(n). What I understood after reading online is that there are two indexes. One index i is for text & another index j is for pattern. And we don't decrement text index i. But we do decrement pattern index j when there is a mismatch & j value is greater than 0. In that case, i remains same. So how can worst time complexity is O(n)? It should be more than that like O(mn). For a specific value of i, we can have multiple iterations of j.
Also what is the best case scenario? Is it different than the worst case scenario? I am looking for an explanation in simple terms as I have already gone through different tutorials.


