LC - KMP alogirthms

Recently practicing hte KMP algorithm, and I think this is really interesting. This alogirthm is a linear time method to find if a string s (say size m) is a substring of t (say size n). A naive approach is to do comparison for each characters using two loops, and the complexity is O(m*n), while using the KMP algorithm, we can reuse the property of string s by pre-building a LSP (longest suffix prefix) with linear time O(m). In this case the comparison can be done in O(n). ...

January 15, 2026 · 4 min