<?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/%e7%90%86%e8%ae%ba%e8%ae%a1%e7%ae%97%e6%9c%ba%e7%ac%94%e8%ae%b0/feed" rel="self" type="application/rss+xml" />
	<link>http://zhiqiang.org/blog</link>
	<description>数学、金融、计算机</description>
	<lastBuildDate>Sat, 19 May 2012 13:47:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>摸箱子问题以及应用</title>
		<link>http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html#comments</comments>
		<pubDate>Tue, 16 Dec 2008 08:24:54 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[概率]]></category>
		<category><![CDATA[游戏]]></category>
		<category><![CDATA[理论计算机笔记]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/posts/boxes-problem-on-static-data-structure-problems.html</guid>
		<description><![CDATA[博客 » 计算机科学 » 概率，游戏，理论计算机笔记 » 系列：理论计算机笔记 查看该系列所有文章 以前提到过，理论计算机这门课会邀请一些正在这边访问的教授来讲课，由于是本科生，所以这些教授一般都是讲些有趣的东西，比如之前的overhang 堆积木 - 能伸出桌面多远？。今天这次课，来自Aarhus的Peter Bro Miltersen讲了一个很有趣的游戏问题。 现在有100个箱子，有一个学生，...]]></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/%e6%a6%82%e7%8e%87" rel="tag">概率</a>，<a href="http://zhiqiang.org/blog/tag/%e6%b8%b8%e6%88%8f" rel="tag">游戏</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" rel="tag">理论计算机笔记</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>以前提到过，理论计算机这门课会邀请一些正在这边访问的教授来讲课，由于是本科生，所以这些教授一般都是讲些有趣的东西，比如之前的<a href="http://zhiqiang.org/blog/science/overhang-stacking-wood-how-far-can-extend-desktop.html">overhang 堆积木 - 能伸出桌面多远？</a>。今天这次课，来自Aarhus的<a href="http://cs.au.dk/~bromille/">Peter Bro Miltersen</a>讲了一个很有趣的游戏问题。</p>
<p>现在有100个箱子，有一个学生，一张写着他的名字的名片被放在某个随机选择的箱子里面。现在这个学生可以检查不超过一半也就是50个箱子，希望能够把它的名字找出来。</p>
<p>很显然，这个学生没有什么好的方法，随机选择50个箱子打开，有一半的概率可以发现含有它的名字纸条的箱子。</p>
<p>OK，现在还是100个箱子，但是有100个学生，写着这些学生的名字的100张纸条随机放入100个箱子里(每个箱子恰好一张纸条)。现在每个学生可以检查不超过一半也就是50个箱子，每个学生希望能找到含有自己名字的箱子。如果在游戏中，所有学生都是独立的（他们不能互相讨论以及看到其他人的开箱结果），问所有学生都实现目标的概率有多大？</p>
<p>如果把每个学生的结果认为是独立的，那么成功的概率只有<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_5deb1f2a4cb23a636322677c5b5711f8.gif' style='vertical-align: middle; border: none; ' class='tex' alt="2^{-100}" /></span><script type='math/tex'>2^{-100}</script>，但其实我们可以做的比这要好得多。事实上，让每个学生都找到含有自己名字的箱子的概率可以高达0.3。</p>
<p>假设学生的名字就是它的编号，从1到100。第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="i" /></span><script type='math/tex'>i</script>个箱子里的编号是<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_337778f4c628d9c80045adbc3a9a81b0.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\pi(i)" /></span><script type='math/tex'>\pi(i)</script>。第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="i" /></span><script type='math/tex'>i</script>个学生这样做：先打开第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="i" /></span><script type='math/tex'>i</script>个箱子，再打开第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_337778f4c628d9c80045adbc3a9a81b0.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\pi(i)" /></span><script type='math/tex'>\pi(i)</script>个箱子，再打开第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_30e74848e17f1241028df30d37626fb5.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\pi(\pi(i))" /></span><script type='math/tex'>\pi(\pi(i))</script>个箱子，以此继续下去，直到发现写着自己名字（也就是<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="i" /></span><script type='math/tex'>i</script>）的纸条或者打开箱子数到达50个为止。</p>
<p>那么当且仅当在<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="i" /></span><script type='math/tex'>i</script>到<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_337778f4c628d9c80045adbc3a9a81b0.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\pi(i)" /></span><script type='math/tex'>\pi(i)</script>这个置换中含有长度超过50的圈时，有学生找不到含有自己名字的箱子。这个概率是<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_8dde40b065bb39ce68f1acf77b65f3d8.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\sum_{j=51}^{100}1/j \sim \ln 2" /></span><script type='math/tex'>\sum_{j=51}^{100}1/j \sim \ln 2</script>（注意一个随机置换里含有一个长度为<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_363b122c528f54df4a0446b6bab05515.gif' style='vertical-align: middle; border: none; ' class='tex' alt="j" /></span><script type='math/tex'>j</script>的圈的概率为<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_f1efbba87e0ef8aba62fd9bfbd5605b8.gif' style='vertical-align: middle; border: none; ' class='tex' alt="1/j" /></span><script type='math/tex'>1/j</script>）。</p>
<p>所以上面策略的成功概率为 <span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_162fba3f0bfe98f043fa4148428acf72.gif' style='vertical-align: middle; border: none; ' class='tex' alt="1-\ln 2 \sim 0.3" /></span><script type='math/tex'>1-\ln 2 \sim 0.3</script>。</p>
<p>类似于以前提到的<a href="http://zhiqiang.org/blog/science/game-one-hat.html">帽子游戏一</a>以及<a href="http://zhiqiang.org/blog/science/game-two-hats.html">帽子游戏二</a>，我们要最大化一个团体都成功的概率，但是每个单个个体成功的概率又是一定的，那么我们只需要设计策略时，让大家要么几乎同时成功，要么几乎同时失败。就像上面的策略里，如果有人失败，意味着排列中有一个长度很大（大于n/2）的圈，这个圈上所有人同时也会失败，通过把失败的实例重合到一起，这样就提高了总体成功的概率。</p>
<p>上面这个问题不是孤立的，它可以应用在static data structure problems的下界证明上。对于后面这个问题，在最近是一个很热门的研究领域，但在这里写了也没人看，知道这个问题的也不需要看，所以我只提一下我们还可以做什么，下面是一个open problem，可以直接得出一个data structure问题的一个下界，是一个可以写学术论文的题目：</p>
<blockquote><p>Open problem：假设现在有<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_21e2c0c0472b331622877accbe29b91b.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="2n" /></span><script type='math/tex'>2n</script>个箱子，<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script>个学生，学生们的名字纸条被放入随机选中的<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script>个箱子里。现在每个学生可以检查不超过一半也就是<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script>个箱子，以找到含有自己名字的箱子。问这时候学生可以采取什么样的策略最大化所有学生都成功找到含有自己名字的箱子的概率。</p>
</blockquote>
<p>期望结果：证明指数级小的下界或者找到常数概率的策略。</p>
<p>有兴趣的可以参考<a href="http://cs.au.dk/~bromille/Papers/succinct.pdf" target="_blank">The cell probe complexity of succinct data structures</a>.</p>
<div><h4>相关文章</h4><ul><li class='currentpost'><a href="http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html">摸箱子问题以及应用</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/theoritical-analysis-marfia-game.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/computer-science/tcs-classroom-notes-database-storage-problems.html">TCS课堂笔记：数据库存储问题</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/memopad/fan-tan-game-empty-when-most-difficult-relationship.html">空当接龙中最难的关</a></li><li ><a href="http://zhiqiang.org/blog/science/15-puzzle.html">15 puzzle</a></li><li ><a href="http://zhiqiang.org/blog/science/two-taking-coins-game.html">取硬币游戏</a></li><li ><a href="http://zhiqiang.org/blog/memopad/cat-game.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/boxes-problem-on-static-data-structure-problems.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html#comments">15 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>征集3个人分蛋糕的方法</title>
		<link>http://zhiqiang.org/blog/science/how-n-people-divide-a-cake-fairly.html</link>
		<comments>http://zhiqiang.org/blog/science/how-n-people-divide-a-cake-fairly.html#comments</comments>
		<pubDate>Tue, 25 Sep 2007 07:54:07 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[自然科学]]></category>
		<category><![CDATA[切蛋糕]]></category>
		<category><![CDATA[头脑风暴]]></category>
		<category><![CDATA[理论计算机笔记]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/posts/how-n-people-divide-a-cake-fairly.html</guid>
		<description><![CDATA[博客 » 自然科学 » 切蛋糕，头脑风暴，理论计算机笔记 » 系列：头脑风暴 查看该系列所有文章 系列：理论计算机笔记 查看该系列所有文章 Yao在课程《理论计算机II》的第一节课上提到的一个问题： 三个人如何平分一块蛋糕？ 要求每个人拿到不少于1/3的蛋糕——这里指的是每个人认为自己拿到的蛋糕价值不少于整块蛋糕的1/3，而每个人对于蛋糕的不同区域的价值认识可能...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/science">自然科学</a> » <a href="http://zhiqiang.org/blog/tag/%e5%88%87%e8%9b%8b%e7%b3%95" rel="tag">切蛋糕</a>，<a href="http://zhiqiang.org/blog/tag/%e5%a4%b4%e8%84%91%e9%a3%8e%e6%9a%b4" rel="tag">头脑风暴</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" rel="tag">理论计算机笔记</a> » </p><div class="series"><span>系列：<b>头脑风暴</b></span><br/>
<a href="http://zhiqiang.org/blog/tag/%e5%a4%b4%e8%84%91%e9%a3%8e%e6%9a%b4">查看该系列所有文章</a>
<div id='series'></div>
</div>  <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>
<p>Yao在课程《理论计算机II》的第一节课上提到的一个问题：</p>
<blockquote><p>三个人如何平分一块蛋糕？</p>
<p>要求每个人拿到不少于1/3的蛋糕——这里指的是每个人认为自己拿到的蛋糕价值不少于整块蛋糕的1/3，而每个人对于蛋糕的不同区域的价值认识可能不同（即并不完全等价于面积）。</p>
<p>方法最好可以推广到n个人的情形。</p>
</blockquote>
<p>课上讲了一种方法：</p>
<blockquote><p>任选一个人，在蛋糕上缓慢移动，直到有人喊停，切下一块给这个喊停的人。直到分完为止，最后一块给最后一个人（没机会喊停了）。</p>
</blockquote>
<p>这个有趣的问题在课堂上引起非常多的讨论，助教被要求在习题课上至少给出6种不同的方法...</p>
<p>请大家帮忙，踊跃发言 <img src='http://zhiqiang.org/blog/wp-includes/images/smilies/smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>[tags]理论计算机课程,切蛋糕,策略[/tags]</p>
<div><h4>相关文章</h4><ul><li class='currentpost'><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/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/computer-science/tcs-classroom-notes-database-storage-problems.html">TCS课堂笔记：数据库存储问题</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/boxes-problem-on-static-data-structure-problems.html">摸箱子问题以及应用</a></li><li ><a href="http://zhiqiang.org/blog/science/37-rule-is-optimal.html">37-rule-is-optimal</a></li><li ><a href="http://zhiqiang.org/blog/science/game-two-hats.html">帽子游戏二</a></li><li ><a href="http://zhiqiang.org/blog/science/rotate-coin-game-solution.html">硬币游戏的答案</a></li><li ><a href="http://zhiqiang.org/blog/science/when-to-stop.html">何时适可而止?</a></li><li ><a href="http://zhiqiang.org/blog/science/a-square-game.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/how-n-people-divide-a-cake-fairly.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/how-n-people-divide-a-cake-fairly.html#comments">13 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/how-n-people-divide-a-cake-fairly.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/%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84" rel="tag">数据结构</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" rel="tag">理论计算机笔记</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 class='currentpost'><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/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/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>
		<item>
		<title>&quot;完美&quot;的洗牌次数 - 7次</title>
		<link>http://zhiqiang.org/blog/science/the-perfect-number-of-shuffling-7-times.html</link>
		<comments>http://zhiqiang.org/blog/science/the-perfect-number-of-shuffling-7-times.html#comments</comments>
		<pubDate>Fri, 15 Dec 2006 04:23:51 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[自然科学]]></category>
		<category><![CDATA[Diaconis]]></category>
		<category><![CDATA[概率]]></category>
		<category><![CDATA[洗牌]]></category>
		<category><![CDATA[理论计算机笔记]]></category>
		<category><![CDATA[随机算法]]></category>
		<category><![CDATA[魔术]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/498.html</guid>
		<description><![CDATA[博客 » 自然科学 » Diaconis，概率，洗牌，理论计算机笔记，随机算法，魔术 » 系列：理论计算机笔记 查看该系列所有文章 在大家玩牌的时候，每一局之前都需要重新洗牌——一次洗牌指将牌分为左右两垛然后穿插放牌，但多少次洗牌才是正当的呢？就我多次打牌的观察，多数人都不超过4次。 但就D. Aldous和P. Diaconis在1992的一个结果，要想达到“比较完美”的洗牌效果——洗...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/science">自然科学</a> » <a href="http://zhiqiang.org/blog/tag/diaconis" rel="tag">Diaconis</a>，<a href="http://zhiqiang.org/blog/tag/%e6%a6%82%e7%8e%87" rel="tag">概率</a>，<a href="http://zhiqiang.org/blog/tag/%e6%b4%97%e7%89%8c" rel="tag">洗牌</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" rel="tag">理论计算机笔记</a>，<a href="http://zhiqiang.org/blog/tag/%e9%9a%8f%e6%9c%ba%e7%ae%97%e6%b3%95" rel="tag">随机算法</a>，<a href="http://zhiqiang.org/blog/tag/%e9%ad%94%e6%9c%af" rel="tag">魔术</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>在大家玩牌的时候，每一局之前都需要重新洗牌——一次洗牌指将牌分为左右两垛然后穿插放牌，但多少次洗牌才是正当的呢？就我多次打牌的观察，多数人都不超过4次。</p>
<p>但就D. Aldous和P. Diaconis<a href="http://www.dartmouth.edu/~chance/course/topics/winning_number.html" target="_blank">在1992的一个结果</a>，要想达到“比较完美”的洗牌效果——洗完牌后牌局基本上随机分布，至少需要5次，要达到“完美”洗牌，则需要7次。但更多次数不会有太多改进。这还是对于一副牌而言的。对于两副牌则需要9次，6副牌需要洗12次。</p>
<p>所用方法是计算图上随机游走达到稳定分布的速度。而这个方法就应用于上面这个结果之后，对于理论计算机的概率算法产生了深远的影响，这也使得P.Diaconis的<a href="http://www.dartmouth.edu/~chance/teaching_aids/books_articles/Mann.pdf" target="_blank">这篇论文</a>超出了它本身看似玩物的领域。</p>
<p>再谈一下<a href="http://www-stat.stanford.edu/~cgates/PERSI/" target="_blank">P. Diaconis</a>，此君14岁离家，去做职业魔术师，没上高中，后来用白天魔术表演挣来的钱晚上念大学课程，最后获得哈佛的博士和斯坦福的教职。另传说中，此人赌技惊人，是赌场不受欢迎之人物。</p>
<div><h4>相关文章</h4><ul><li class='currentpost'><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/computer-science/boxes-problem-on-static-data-structure-problems.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/resource/magics-in-2009-spring-festival-gala.html">2009年的春节晚会魔术</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/computer-science/tcs-classroom-notes-database-storage-problems.html">TCS课堂笔记：数据库存储问题</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/to-active-the-brain-active.html">来活跃活跃大脑</a></li><li ><a href="http://zhiqiang.org/blog/science/theoritical-analysis-marfia-game.html">杀人的理论分析</a></li><li ><a href="http://zhiqiang.org/blog/review/fooled-by-randomnes.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>, 2006. | <a href="http://zhiqiang.org/blog/science/the-perfect-number-of-shuffling-7-times.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/the-perfect-number-of-shuffling-7-times.html#comments">6 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/the-perfect-number-of-shuffling-7-times.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>TCS: 拜占庭将军问题 (The Byzantine Generals Problem)</title>
		<link>http://zhiqiang.org/blog/science/computer-science/tcs-byzantine-failure-the-byzantine-generals-problem.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/tcs-byzantine-failure-the-byzantine-generals-problem.html#comments</comments>
		<pubDate>Fri, 22 Sep 2006 05:08:45 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[The Byzantine Generals Problem]]></category>
		<category><![CDATA[拜占庭将军问题]]></category>
		<category><![CDATA[理论计算机笔记]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/449.html</guid>
		<description><![CDATA[博客 » 计算机科学 » The Byzantine Generals Problem，拜占庭将军问题，理论计算机笔记 » 系列：理论计算机笔记 查看该系列所有文章 这个问题在Yao的理论计算机课上整整讨论了2节课。它是一个算法设计问题，也极具趣味性。下面是它的一些介绍和解决方案([1])。 拜占庭帝国就是5～15世纪的东罗马帝国，拜占庭即现在土耳其的伊斯坦布尔。我们可以想象，拜占庭军队有许多分支，...]]></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/the-byzantine-generals-problem" rel="tag">The Byzantine Generals Problem</a>，<a href="http://zhiqiang.org/blog/tag/%e6%8b%9c%e5%8d%a0%e5%ba%ad%e5%b0%86%e5%86%9b%e9%97%ae%e9%a2%98" rel="tag">拜占庭将军问题</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" rel="tag">理论计算机笔记</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>这个问题在Yao的理论计算机课上整整讨论了2节课。它是一个算法设计问题，也极具趣味性。下面是它的一些介绍和解决方案([<a href="#ref" target="_blank">1</a>])。</p>
<p>拜占庭帝国就是5～15世纪的东罗马帝国，拜占庭即现在土耳其的伊斯坦布尔。我们可以想象，拜占庭军队有许多分支，驻扎在敌人城外，每一分支由各自的将军指挥。将军们只能靠通讯员进行通讯。在观察了敌人以后，忠诚的将军们必须制订一个统一的行动计划——进攻或者撤退。然而，这些将军中有叛徒，他们不希望忠诚的将军们能达成一致，因而影响统一行动计划的制订与传播。问题是：将军们必须有一个协议，使所有忠诚的将军们能够达成一致，而且少数几个叛徒不能使忠诚的将军们做出错误的计划——使有些将军进攻而另一些将军撤退了。</p>
<p>抽象出来，可以表述成：</p>
<blockquote><p><strong>拜占庭将军问题</strong>：设计一个协议，一个司令要送一个命令给他的n-1个副官，使得<br />
IC1. 所有忠诚的副官遵守同一个命令。<br />
IC2. 假如司令是忠诚的，则每一个忠诚的副官遵守他送出的该命令。</p>
<p>约定：忠诚的将军将遵守协议，而叛徒则可能破坏协议，尽可能的干绕其它人的判断。叛徒是匿名的。而且最后不需要确定谁是叛徒。</p></blockquote>
<p>注意司令也有可能是叛徒，所以IC2与IC1是不同的。</p>
<p>递归设计协议OM(n, m)为</p>
<blockquote><p>OM(n, 0):</p>
<ol>
<li>司令发送命令给所有副官。</li>
<li>副官按照接收到的命令行事。</li>
</ol>
<p>OM(n, m):</p>
<ol>
<li>司令发送命令给所有副官，设副官i收到命令vi。</li>
<li>分为独立的n-1轮：对每个副官i，将其视为司令，使用协议A(n-1, m-1)将vi发送到所有其它副官。</li>
<li>这样每个副官都收到n-1条信息，每个副官都按照出现次数更多的命令行事（如果进攻和撤退的命令一样多，则默认取撤退）。</li>
</ol>
</blockquote>
<p>递归证明</p>
<blockquote><p>引理：当n&gt;2m+k，n个将军中至多k个叛徒，协议A(n, m)满足IC2，即司令是忠诚的，每个忠诚的副官将会执行司令的命令。</p></blockquote>
<p>进而说明：</p>
<blockquote><p>当n&gt;3m时，n个将军，且至多m个叛徒，协议A(n, m)可以同时满足IC1和IC2。</p></blockquote>
<p>更深刻的结论：</p>
<blockquote><p>当n&lt;=3m时，n个将军中的m个叛徒可以让将军们无法达成一致，也就是满足IC1和IC2的协议不可能存在。</p></blockquote>
<p>参考：</p>
<ol id="ref">
<li><a href="http://dl.acm.org/citation.cfm?id=357176" target="_blank">The Byzantine Generals Problem</a>, the first paper involved</li>
<li>可信计算VII:拜占庭将军问题</li>
<li><a href="http://en.wikipedia.org/wiki/Byzantine_failure">Byzantine failure - Wikipedia, the free encyclopedia</a></li>
</ol>
<p>PS: 标题里TCS是<a href="http://en.wikipedia.org/wiki/Theoretical_computer_science" target="_blank">Theoretical Computer Science</a>(理论计算机科学)的缩写，这篇文章同属于<a href="http://zhiqiang.org/blog/science/computer-science/preliminary-computer-theory-preface.html">理论计算机介绍系列文章</a>，算作<a href="http://zhiqiang.org/blog/search.php?q=%E7%90%86%E8%AE%BA%E8%AE%A1%E7%AE%97%E6%9C%BA">理论计算机初步系列</a>文章的补充吧。</p>
<div><h4>相关文章</h4><ul><li class='currentpost'><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/computer-science/tcs-classroom-notes-database-storage-problems.html">TCS课堂笔记：数据库存储问题</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>, 2006. | <a href="http://zhiqiang.org/blog/science/computer-science/tcs-byzantine-failure-the-byzantine-generals-problem.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/tcs-byzantine-failure-the-byzantine-generals-problem.html#comments">5 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/tcs-byzantine-failure-the-byzantine-generals-problem.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

