<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Kmp on Yu-Cheng's Notes</title><link>https://linkingmon.github.io/blog/tags/kmp/</link><description>Recent content in Kmp on Yu-Cheng's Notes</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Thu, 15 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://linkingmon.github.io/blog/tags/kmp/index.xml" rel="self" type="application/rss+xml"/><item><title>LC - KMP alogirthms</title><link>https://linkingmon.github.io/blog/coding/lc-kmp/</link><pubDate>Thu, 15 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-kmp/</guid><description>&lt;p&gt;Recently practicing hte KMP algorithm, and I think this is really interesting.&lt;/p&gt;
&lt;p&gt;This alogirthm is a linear time method to find if a string &lt;code&gt;s&lt;/code&gt; (say size m) is a substring of &lt;code&gt;t&lt;/code&gt; (say size n).&lt;/p&gt;
&lt;p&gt;A naive approach is to do comparison for each characters using two loops, and the complexity is &lt;code&gt;O(m*n)&lt;/code&gt;, while using the KMP algorithm, we can reuse the property of string &lt;code&gt;s&lt;/code&gt; by pre-building a LSP (longest suffix prefix) with linear time &lt;code&gt;O(m)&lt;/code&gt;. In this case the comparison can be done in &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>