<?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>阅微堂 &#187; 数据结构</title>
	<atom:link href="http://zhiqiang.org/blog/tag/%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84/feed" rel="self" type="application/rss+xml" />
	<link>http://zhiqiang.org/blog</link>
	<description>理工科背景的证券从业人员</description>
	<lastBuildDate>Sun, 05 Feb 2012 03:59:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>编程的核心是数据结构，而不是算法</title>
		<link>http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html#comments</comments>
		<pubDate>Thu, 28 Feb 2008 00:15:24 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[数据结构]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/posts/programs-depend-on-date-struct-not-algorithm.html</guid>
		<description><![CDATA[博客 » 计算机科学 » 算法 » Rob Pike, 最伟大的 C 语言大师之一 , 在Notes on C Programming(英文原文)中从另一个稍微不同的角度表述了 Unix 的哲学: 你无法断定程序会在什么地方耗费运行时间。瓶颈经常出现在想不到的地方，所以别急于胡乱找个地方改代码，除非你已经证实那儿就是瓶颈所在。 估量。在你没对代码进行估量，特别是没找到最耗时的那部分之前，别去优化速度。 花...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/science/computer-science">计算机科学</a> » <a href='http://zhiqiang.org/blog/tag/%e7%ae%97%e6%b3%95'>算法</a>  » </p><p>Rob Pike, 最伟大的 C 语言大师之一 , 在<em>Notes on C Programming</em>(<a href="http://www.lysator.liu.se/c/pikestyle.html" target="_blank">英文原文</a>)中从另一个稍微不同的角度表述了 Unix 的哲学:
<ol>
<li>你无法断定程序会在什么地方耗费运行时间。瓶颈经常出现在想不到的地方，所以别急于胡乱找个地方改代码，除非你已经证实那儿就是瓶颈所在。  </li>
<li>估量。在你没对代码进行估量，特别是没找到最耗时的那部分之前，别去优化速度。  </li>
<li>花哨的算法在 n 很小时通常很慢，而 n 通常很小。花哨算法的常数复杂度很大。除非你确定 n 总是很大，否则不要用花哨算法（即使 n 很大，也优先考虑原则 2 ）。  </li>
<li>花哨的算法比简单算法更容易出 bug 、更难实现。尽量使用简单的算法配合简单的数据结构。  </li>
<li>数据压倒一切。如果已经选择了正确的数据结构并且把一切都组织得井井有条，正确的算法也就不言自明。编程的核心是数据结构，而不是算法。  </li>
<li>没有原则 6 。 </li>
</ol>
<p>Ken Thompson —— Unix 最初版本的设计者和实现者，禅宗偈语般地对 Pike 的原则4 作了强调：  </p>
<p align="center"><strong><font size="4">拿不准就穷举</font></strong></p>
<p>via: newsmth-algorithm</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/science/computer-science/tcs-classroom-notes-database-storage-problems.html">TCS课堂笔记：数据库存储问题</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/preliminary-computer-theory-algorithms-and-calculation-model.html">理论计算机初步：算法和计算模型</a></li><li><a href="http://zhiqiang.org/blog/science/mathmatics-in-rubik-cube-and-algorithm.html">魔方里的数学</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/graph-isomorphism-is-polynomial.html">图同构问题属于P？</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/complexity-of-prime-sieve.html">素数筛法的复杂度</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html">Perfect Shuffle的算法</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/median-algorithm-of-ordered-matrix.html">有序矩阵的中位数算法</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/download-encyclopedia-of-algorithm.html">算法百科全书 - Encyclopedia of Algorithms</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/inverse-square-root-algorithm-analysis.html">求平方根倒数的算法</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/max-drawdown-algorithm.html">最大回撤和最大短期回撤的线性算法</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2008. | <a href="http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html#comments">13 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>TCS课堂笔记：数据库存储问题</title>
		<link>http://zhiqiang.org/blog/science/computer-science/tcs-classroom-notes-database-storage-problems.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/tcs-classroom-notes-database-storage-problems.html#comments</comments>
		<pubDate>Tue, 08 May 2007 10:04:13 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[数据结构]]></category>
		<category><![CDATA[理论计算机笔记]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/587.html</guid>
		<description><![CDATA[博客 » 计算机科学 » 理论计算机笔记 » 系列：理论计算机笔记 查看该系列所有文章 理论计算机(I)课上讲的一个问题，很有意思。 已经一个n，m和里n个数，设计一种保存这n个元素的表的数据结构形式，使得对中任何一个数，可以最少的查询次数（每次查询，可以选择一个位置，然后你能知道表中这个位置的数据），获知这个数是否在表中。 如果设计这个表为有序表，用二...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/science/computer-science">计算机科学</a> » <a href='http://zhiqiang.org/blog/tag/%e7%90%86%e8%ae%ba%e8%ae%a1%e7%ae%97%e6%9c%ba%e7%ac%94%e8%ae%b0'>理论计算机笔记</a>  » </p><div class="series"><span>系列：<b>理论计算机笔记</b></span><br/>
<a href="http://zhiqiang.org/blog/tag/%e7%90%86%e8%ae%ba%e8%ae%a1%e7%ae%97%e6%9c%ba%e7%ac%94%e8%ae%b0">查看该系列所有文章</a>
<div id='series'></div>
</div>  <p>理论计算机(I)课上讲的一个问题，很有意思。</p>
<p>已经一个n，m和<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_d43069858d2a796ab1b977f3684de967.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\{1,2,\cdots, m\}" /></span><script type='math/tex'>\{1,2,\cdots, m\}</script>里n个数，设计一种保存这n个元素的表的数据结构形式，使得对<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_d43069858d2a796ab1b977f3684de967.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\{1,2,\cdots, m\}" /></span><script type='math/tex'>\{1,2,\cdots, m\}</script>中任何一个数，可以最少的查询次数（每次查询，可以选择一个位置，然后你能知道表中这个位置的数据），获知这个数是否在表中。</p>
<p>如果设计这个表为有序表，用二分法需要<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_0d2e858bd7f89eed5461e5637d6e0a50.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\log n" /></span><script type='math/tex'>\log n</script>次查询。</p>
<p>有序表是最优的么？</p>
<p>举一个例子，一个保存1，2，3里面的两个数的有序表，要想知道2是否在这个表里面，至少需要两次查询。可不可以用一种特定的数据结构，使得一次查询就能判定任何一个数是不是在数据库里面？</p>
<p>结论是可能的，见下图：</p>
<p align="center"><a title="sorted table" href="http://www.flickr.com/photos/51234757@N00/489673515/"><img alt="sorted table" src="http://farm1.static.flickr.com/189/489673515_9cc3702472.jpg" border="0"/></a></p>
<p>一般的，假如表里的n个数的范围是1，2，...，2n-2，即<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_01e42101c7214aaa22d1f8fc3eeb5a15.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="m=2n-2" /></span><script type='math/tex'>m=2n-2</script>，可以设计一种方法，使得，对于任何一个数，<strong>只需要查询一次</strong>，便能知道这个数是否在这个表里面。</p>
<p>课堂上有同学当场就想出设计方法，向他致敬！</p>
<p>另外，利用广义的Ramsey定理，对于固定的n，能够证明当m足够大时，无论你怎么设计那个表的结构，也至少需要<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_0d2e858bd7f89eed5461e5637d6e0a50.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\log n" /></span><script type='math/tex'>\log n</script>的查询次数。</p>
<p>一个很神奇的问题。相关论文<a href="http://www.cs.umd.edu/~gasarch/BLOGPAPERS/tables.pdf" target="_blank">Should Table be Sorted?</a>, 上面的图片也来自这篇文章。</p>
<p>[tags]数据库,理论计算机[/tags]</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html">编程的核心是数据结构，而不是算法</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/tcs-byzantine-failure-the-byzantine-generals-problem.html">TCS: 拜占庭将军问题 (The Byzantine Generals Problem)</a></li><li><a href="http://zhiqiang.org/blog/science/the-perfect-number-of-shuffling-7-times.html">&quot;完美&quot;的洗牌次数 - 7次</a></li><li><a href="http://zhiqiang.org/blog/science/tcs-classroom-notes-the-best-dating-strategy.html">最佳约会策略</a></li><li><a href="http://zhiqiang.org/blog/science/how-n-people-divide-a-cake-fairly.html">征集3个人分蛋糕的方法</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html">摸箱子问题以及应用</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2007. | <a href="http://zhiqiang.org/blog/science/computer-science/tcs-classroom-notes-database-storage-problems.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/tcs-classroom-notes-database-storage-problems.html#comments">6 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/tcs-classroom-notes-database-storage-problems.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

