<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>kmp算法</title>
	<atom:link href="https://www.aitaocui.cn/tag/181538/feed" rel="self" type="application/rss+xml" />
	<link>https://www.aitaocui.cn</link>
	<description>翡翠玉石爱好者聚集地</description>
	<lastBuildDate>Wed, 23 Nov 2022 07:47:50 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>

<image>
	<url>https://www.aitaocui.cn/wp-content/uploads/2022/11/taocui.png</url>
	<title>kmp算法</title>
	<link>https://www.aitaocui.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>kmp算法(改进的字符串匹配算法)</title>
		<link>https://www.aitaocui.cn/article/285314.html</link>
					<comments>https://www.aitaocui.cn/article/285314.html#respond</comments>
		
		<dc:creator><![CDATA[大吉岭]]></dc:creator>
		<pubDate>Wed, 23 Nov 2022 07:47:50 +0000</pubDate>
				<category><![CDATA[百科]]></category>
		<category><![CDATA[kmp算法]]></category>
		<guid isPermaLink="false">https://www.aitaocui.cn/?p=285314</guid>

					<description><![CDATA[KMP算法是一种改进的字符串匹配算法，由D.E.Knuth，J.H.Morris和V.R.Pratt同时发现，因此人们称它为克努特——莫里斯——普拉特操作（简称KMP算法）。KMP...]]></description>
										<content:encoded><![CDATA[</p>
<article>
<p>KMP算法是一种改进的字符串匹配算法，由D.E.Knuth，J.H.Morris和V.R.Pratt同时发现，因此人们称它为克努特——莫里斯——普拉特操作（简称KMP算法）。KMP算法的关键是利用匹配失败后的信息，尽量减少模式串与主串的匹配次数以达到快速匹配的目的。具体实现就是实现一个next()函数，函数本身包含了模式串的局部匹配信息。</p>
</article>
<article>
<h1>背景</h1>
<p>给定一个主串（以 S 代替）和模式串（以 P 代替），要求找出 P 在 S 中出现的位置，此即串的模式匹配问题。</p>
<p>Knuth-Morris-Pratt 算法（简称 KMP）是解决这一问题的常用算法之一，这个算法是由高德纳（Donald Ervin Knuth）和沃恩·普拉特在 1974 年构思，同年詹姆斯·H·莫里斯也独立地设计出该算法，最终三人于 1977 年联合发表。</p>
<h1>基本思想</h1>
<p>假设在模式匹配的进程中，执行T[i]和W[j]的匹配检查。若T[i]=W[j]，则继续检查T[i+1]和W[j+1]是否匹配。若T[i]&lt;&gt;W[j]，则分成两种情况：若j=1，则模式串右移一位，检查T[i+1]和W是否匹配；若1&lt;=m，则模式串右移j-next(j）位，检查T[i]和W[next(j)]是否匹配。重复此过程直到j=m或i=n结束。</p>
<p>文献中，朱洪对KMP算法作了修改，他修改了KMP算法中的next函数，即求next函数时不但要求W[1,next(j)-1]=W[j-(next(j)-1），j-1]，而且要求W[next(j)]&lt;&gt;W[j]，他记修改后的next函数为newnext。显然在模式串字符重复高的情况下，朱洪的KMP算法比KMP算法更加有效。</p>
<p>以下给出朱洪的改进KMP算法和next函数和newnext函数的计算算法。</p>
<h1>KMP串匹配算法</h1>
<p>输入：正文串j和模式串W[1,m]</p>
<p>输出：匹配结果match[1,n]</p>
</article>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aitaocui.cn/article/285314.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
