<?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>一花一世界</title>
	<atom:link href="http://www.juliuschen.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.juliuschen.com</link>
	<description>谈笑间，樯橹灰飞烟灭</description>
	<lastBuildDate>Wed, 09 Jun 2010 13:44:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>KMP算法</title>
		<link>http://www.juliuschen.com/archives/21.html</link>
		<comments>http://www.juliuschen.com/archives/21.html#comments</comments>
		<pubDate>Sun, 24 Jan 2010 06:27:25 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Strings]]></category>
		<category><![CDATA[KMP算法]]></category>
		<category><![CDATA[前缀函数]]></category>
		<category><![CDATA[字符串算法]]></category>
		<category><![CDATA[有限自动机]]></category>
		<category><![CDATA[模式匹配]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/21.html</guid>
		<description><![CDATA[KMP算法是字符串匹配的一种改进算法，在1977年由D. E. Knuth，J. H. Morris和V. R. Pratt一起提出，并以他们名字的首字母命名。和朴素的模式匹配算法相比，KMP算法最大的特点就是主串指针不回溯。它利用已经得到的“部分匹配”信息来减少不必要的比较而加快字符串的匹配速度。 KMP算法的本质 KMP算法本质上是实现了对自动机的模拟。它通过构造一个有限自动机来搜寻某给定的模式在正文中出现的位置。整个算法的核心就是对自动机的构建（或前缀函数的构建，KMP算法不用计算变迁函数，而是根据模式预先计算出一个辅助函数next来实现更快速的状态切换），当完成有限自动机的构建之后对主串的搜寻就显得很简单了。 前缀函数next的构建 模式的前缀函数包含有模式与其自身的位移进行匹配的信息。这些信息可用于避免在朴素的模式匹配算法中对无用位移的测试。比如主串和模式串在主串指针为Ti、模式串指针为Pj处匹配失败时，可以主串指针不回溯并直接取next函数的值next[j] = k将模式串向右滑动到第k个字符处重新开始比较，而不用去做无用位移的测试。只是这样的操作能成立k必须要满足一定的条件，如下所示： 首先，如果模式串能直接向右滑动到第k个字符处重新开始比较则说明模式串中的前k-1个字符必然已经和主串匹配了，也即必然已经有下面式子，且为了能最大化的向右移动则不能存在更大的k&#8217;满足下面式子： ： P1 P2 &#8230; Pk-1 = Ti-k+1 Ti-k+2 &#8230; Ti-1 而由已经比较所得的“部分匹配”信息可知： ： Pj-k+1 Pj-k+2 &#8230; Pj-1 = Ti-k+1 Ti-k+2 &#8230; Ti-1 因此由式子和式子我们可以推得： ： P1 P2 &#8230; Pk-1 = Pj-k+1 Pj-k+2 &#8230; Pj-1 也就是k必须要满足式子的条件！由这个式子也可以看出k就是模式中第j个字符所拥有的最长真后缀同时是模式前缀的串的长度，且k的取值和主串T无关！ 那有了式子之后如何去求模式的每个字符所对应的k(next[j])的值呢？ 由上面结论可知，当j = 0时next[j] = -1，因为第一个字符没有真后缀同时是模式的前缀。其他情况时，next[j]则可以由它前一个位置字符的next值推出。 比如我们要求next[j+1]，假设已有next[j] = [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/21.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>朴素模式匹配算法</title>
		<link>http://www.juliuschen.com/archives/20.html</link>
		<comments>http://www.juliuschen.com/archives/20.html#comments</comments>
		<pubDate>Sat, 23 Jan 2010 12:41:59 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Strings]]></category>
		<category><![CDATA[Brute-Force算法]]></category>
		<category><![CDATA[字符串算法]]></category>
		<category><![CDATA[模式匹配]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/20.html</guid>
		<description><![CDATA[朴素模式匹配算法又称简单匹配算法或Brute-Force算法，它是字符串模式匹配中比较简单的一种算法。它从主串的第一个字符开始进行模式匹配，依次比较主串和模式串中的每个字符，若比较全部相等（模式匹配成功），则返回模式串中第一个字符在主串中的位置，否则主串指针从比较失败的字符处回溯到第二个字符开始重新和模式串进行匹配，这样依此下去，直到和模式串匹配成功或到主串的末尾（匹配不成功）为止。 朴素模式匹配算法的C/C++代码实现： // 定义一个字符串结构体 typedef struct&#160; { &#160; &#160; char&#160;data[MAX_SIZE]; &#160; &#160; int&#160;length; }&#160;string; &#160; int&#160;BruteForce(string s, string t) { &#160; &#160; int&#160;i = 0, j = 0; &#160; &#160; while&#160;(i &#60; s.length &#38;&#38; j &#60; t.length) { &#160; &#160; &#160; &#160; if&#160;(s[i] == t[j]) { &#160; &#160; &#160; &#160; &#160; &#160; i++; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/20.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>字符串函数</title>
		<link>http://www.juliuschen.com/archives/18.html</link>
		<comments>http://www.juliuschen.com/archives/18.html#comments</comments>
		<pubDate>Sat, 16 Jan 2010 08:19:14 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[String]]></category>
		<category><![CDATA[字符串函数]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/18</guid>
		<description><![CDATA[几个常见字符串处理函数 /* * * str开头的函数部分 * In the following functions, variables s and t are of type char *; * cs and ct are of type const char *; n is of type size_t; * and c is an int converted to char. */ &#160; // strcpy - copy string ct to string s, including [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/18.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>基数排序</title>
		<link>http://www.juliuschen.com/archives/15.html</link>
		<comments>http://www.juliuschen.com/archives/15.html#comments</comments>
		<pubDate>Fri, 25 Dec 2009 09:54:43 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[基数排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[非比较排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/15</guid>
		<description><![CDATA[基数排序和计数排序一样，是非基于比较的排序算法，它借助“分配”和“收集”两种操作对单逻辑关键字进行排序（基于箱/桶排序），它的排序速度很快，时间复杂度为线性，但由于需要的辅助空间太大（n(radix+1)），因此长期无法应用。直到1954年有人提出用“计数”代替“分配”才得以使它能在计算机上实现。此后，又有人提出用链表作为存储数据的结构，这样又能减少一些辅助空间，这也是一种比较好的实现方法（只是算法要较复杂）。 基数排序分为MSD（最高位优先）基数排序和LSD（最低位优先）基数排序，MSD从左到右处理关键字的位数，首先处理最重要的数字。它比较符合常规的思维，所需处理的信息量也较少。但按MSD进行排序，必须将序列逐层分割成若干个子序列，然后对各子序列分别进行排序；而LSD则从右到左先处理最不重要的数字，这样虽然可能花费了一些时间来处理不会影响结果的信息，但它不用分子序列，对每个关键字都是整个序列参加排序，而且对具体的应用还可以对其进行改进。因此在很多排序应用中都选择这种方法。 基数排序（LSD/用计数排序）的C/C++代码实现： void radix_sort(int a[], int length) { &#160; &#160; int&#160;i, j, digit; &#160; &#160; int&#160;c[16]; &#160; &#160; int&#160;temp[ARRAY_SIZE]; &#160; &#160; for&#160;(i = 0; i &#60; HEX; ++i) { &#160; &#160; &#160; &#160; for&#160;(j = 0; j &#60; 16; ++j) c[j] = 0; &#160; &#160; &#160; &#160; for&#160;(j = 0; j &#60; length; ++j) [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/15.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>计数排序</title>
		<link>http://www.juliuschen.com/archives/14.html</link>
		<comments>http://www.juliuschen.com/archives/14.html#comments</comments>
		<pubDate>Thu, 24 Dec 2009 10:34:17 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[计数排序]]></category>
		<category><![CDATA[非比较排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/14</guid>
		<description><![CDATA[计数排序(Counting Sort)是一种非基于比较的排序方法，它要求所有的待排元素都必须是≥0的整数。它的排序步骤是首先根据数组中最大的元素值加1作为长度来定义一个计数数组C。然后统计待排数组中每个值为i的元素出现的次数，存入C的第i项中。再对所有的计数累加（从C中的第一项开始，每一项和前一项相加）。最后再反向填充辅助数组：将每个元素i放在辅助数组的第C(i)项，每放一个元素就将C(i)减去1。这样完成之后排序就已完毕，有序序列已存储在辅助数组中。如果结果想用原数组输出，则将它们从辅助数组考回到原数组即可。 计数排序的C/C++代码实现： void counting_sort(int a[], int length) { &#160; &#160; int&#160;i; &#160; &#160; int&#160;c[MAX_VALUE] = {0}; &#160; &#160; int&#160;temp[ARRAY_SIZE] = {0}; &#160; &#160; for&#160;(i = 0; i &#60; length; ++i) c[a[i]]++; &#160; &#160; for&#160;(i = 1; i &#60; MAX_VALUE; ++i) c[i] += c[i-1]; &#160; &#160; for&#160;(i = length - 1; i &#62;= 0; --i) [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/14.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>归并排序</title>
		<link>http://www.juliuschen.com/archives/13.html</link>
		<comments>http://www.juliuschen.com/archives/13.html#comments</comments>
		<pubDate>Tue, 22 Dec 2009 10:27:11 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[归并排序]]></category>
		<category><![CDATA[排序算法]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/13</guid>
		<description><![CDATA[归并排序是建立在归并操作（Merging）上的一种排序方法，它是采用分治法的一个非常典型的应用。归并是指将两个或两个以上的有序表合并成一个新的更大的有序表，归并排序则是递归的先将待排序列分割成n个序列，然后从最小的有序序列（只含一个元素）开始不断调用归并操作进行合并直到最后都合并成一个大的完整的有序表为止。 归并排序的C/C++代码实现： void merge(int array[], int low, int m, int high) { &#160; &#160; int&#160;i, j, k; &#160; &#160; static&#160;int temp[ARRAY_SIZE]; &#160; &#160; for&#160;(i = low, j = m + 1, k = 0; k &#60; high - low + 1; ++k) { &#160; &#160; &#160; &#160; if&#160;(i &#62; m) { &#160; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/13.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>堆排序</title>
		<link>http://www.juliuschen.com/archives/12.html</link>
		<comments>http://www.juliuschen.com/archives/12.html#comments</comments>
		<pubDate>Mon, 21 Dec 2009 10:12:45 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[堆排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[选择排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/12</guid>
		<description><![CDATA[堆排序是对树形选择排序的改进，它首先将整个待排序列构建成一个堆，然后将堆顶元素与最后一个元素交换，由此得到一个有序元素和一个长度减1的堆。由于交换后新的堆顶元素可能不满足堆的定义，因此需要将新的堆重新进行堆化（堆化无需重新建堆，只需做少许调整），在堆化完成之后再次将堆顶元素与堆的最后一个元素交换，由此再得到一个新的有序元素和一个长度减1的堆。然后再重新进行堆化，再交换。。。这样一直下去，直到整个堆只有一个元素为止。这样也就完成了对序列的排序。由这个排序的过程也可以知道，堆排序和简单选择排序不同，不是从前往后慢慢有序，而是从后往前慢慢有序。 堆排序的C/C++代码实现： void heapify(int sort_array[], int k, int m) { &#160; &#160; int&#160;temp = sort_array[k]; &#160; &#160; for&#160;(int j = 2 * k; j &#60;= m; j *= 2) { &#160; &#160; &#160; &#160; if&#160;(j &#60; m &#38;&#38; sort_array[j] &#60; sort_array[j+1]) ++j; &#160; &#160; &#160; &#160; if&#160;(!(temp &#60; sort_array[j])) break; &#160; &#160; &#160; &#160; sort_array[k] [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>快速排序</title>
		<link>http://www.juliuschen.com/archives/11.html</link>
		<comments>http://www.juliuschen.com/archives/11.html#comments</comments>
		<pubDate>Sun, 20 Dec 2009 07:50:37 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[交换排序]]></category>
		<category><![CDATA[快速排序]]></category>
		<category><![CDATA[排序算法]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/11</guid>
		<description><![CDATA[快速排序是应用最广泛的排序算法，也是目前认为最好的一种内部排序方法（就平均时间而言）。它采用分治（divide-and-conquer）的策略，通过一趟排序将待排记录分割成独立的两个部分，使其中的一部分记录关键字均比另一部分记录关键字小（大），然后分别对两个部分继续进行排序，以达到整个序列有序。 快速排序的C/C++代码实现： int partition(int sort_array[], int low, int high) { &#160; &#160; int&#160;pivotkey = sort_array[low]; &#160; &#160; while&#160;(low &#60; high) { &#160; &#160; &#160; &#160; while&#160;(low &#60; high &#38;&#38; pivotkey &#60;= sort_array[high]) --high; &#160; &#160; &#160; &#160; sort_array[low] = sort_array[high]; &#160; &#160; &#160; &#160; while&#160;(low &#60; high &#38;&#38; pivotkey &#62;= sort_array[low]) ++low; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/11.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>希尔排序</title>
		<link>http://www.juliuschen.com/archives/10.html</link>
		<comments>http://www.juliuschen.com/archives/10.html#comments</comments>
		<pubDate>Tue, 15 Dec 2009 12:37:25 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[希尔排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[插入排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/10</guid>
		<description><![CDATA[希尔排序是插入排序的扩展。希尔排序的一个特点是：子序列的构成不是简单的逐段分割，而是将相隔某个增量的记录组成一个子序列。希尔排序的一个关键是：其步长（也就是增量）的取法，通常认为步长序列中的数字互质很重要。 希尔排序的C/C++代码实现： void shell_insert(int sort_array[], int length, int h) { &#160; &#160; int&#160;i, j, temp; &#160; &#160; for&#160;(i = h; i &#60; length; ++i) &#160; &#160; &#160; &#160; if&#160;(sort_array[i] &#60; sort_array[i-h]) { &#160; &#160; &#160; &#160; &#160; &#160; temp = sort_array[i]; &#160; &#160; &#160; &#160; &#160; &#160; sort_array[i] = sort_array[i-h]; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/10.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>简单排序方法</title>
		<link>http://www.juliuschen.com/archives/9.html</link>
		<comments>http://www.juliuschen.com/archives/9.html#comments</comments>
		<pubDate>Mon, 14 Dec 2009 15:03:55 +0000</pubDate>
		<dc:creator>Julius Chen</dc:creator>
				<category><![CDATA[Sorting]]></category>
		<category><![CDATA[交换排序]]></category>
		<category><![CDATA[冒泡排序]]></category>
		<category><![CDATA[排序算法]]></category>
		<category><![CDATA[插入排序]]></category>
		<category><![CDATA[直接插入排序]]></category>
		<category><![CDATA[简单选择排序]]></category>
		<category><![CDATA[选择排序]]></category>

		<guid isPermaLink="false">http://www.juliuschen.com/archives/9</guid>
		<description><![CDATA[简单的排序方法主要是指直接插入排序、冒泡排序和简单选择排序。他们都是稳定的排序方法，平均时间复杂度都为O(n2)，并且空间复杂度都为O(1)。 直接插入排序 直接插入排序（Straight Insertion Sort）是一种最简单的排序方法，它的基本操作是将一个记录插入到已排好序的有序表中，从而得到一个新的、记录数增1的有序表。直接插入排序的运行时间和数据原始排列顺序密切相关。对于已经排好序（或已几乎排好序）的数据，插入排序的效率会比较高。 直接插入排序的C/C++代码实现： void insert_sort(int sort_array[], int length) { &#160; &#160; int&#160;i, j; &#160; &#160; for&#160;(i = 2; i &#60; length; ++i) &#160; &#160; &#160; &#160; if&#160;(sort_array[i] &#60; sort_array[i-1]) { &#160; &#160; &#160; &#160; &#160; &#160; sort_array[0] = sort_array[i]; &#160; &#160; &#160; &#160; &#160; &#160; sort_array[i] = sort_array[i-1]; &#160; &#160; &#160; &#160; [...]]]></description>
		<wfw:commentRss>http://www.juliuschen.com/archives/9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
