<?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; memo</title>
	<atom:link href="http://zhiqiang.org/blog/tag/memo/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>Perfect Shuffle的算法</title>
		<link>http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html#comments</comments>
		<pubDate>Tue, 01 Apr 2008 00:35:27 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[perfect shuffle]]></category>
		<category><![CDATA[算法]]></category>
		<category><![CDATA[面试题]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/posts/perfect-shuffle%e7%9a%84%e7%ae%97%e6%b3%95.html</guid>
		<description><![CDATA[博客 » 计算机科学 » 算法 » 系列：面试题 查看该系列所有文章 珍爱生命，远离政治。我们继续讨论算法。 2008/04/01补充：此算法有重大缺陷。详情请见留言部分。 一年前，我们讨论过一个算法问题，perfect shuffle，据称是个微软面试题： 输入，如何用的时间，的空间，将这个序列顺序改为。 那一次讨论我们翻出了问题的来源，一篇长达12页的论文Computing the Cycles in the Perfect S...]]></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><div class="series"><span>系列：<b>面试题</b></span><br/>
<a href="http://zhiqiang.org/blog/tag/%e9%9d%a2%e8%af%95%e9%a2%98">查看该系列所有文章</a>
<div id='series'></div>
</div>  <p>珍爱生命，远离政治。我们继续讨论算法。</p>
<p><strong>2008/04/01补充：此算法有重大缺陷。详情请见留言部分。</strong></p>
<p>一年前，我们讨论过一个算法问题，perfect shuffle，据称是个微软面试题：</p>
<blockquote><p>输入<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_b50799dad81f21d20410095ecd84c892.gif' style='vertical-align: middle; border: none; ' class='tex' alt="a_1,a_2,\cdots,a_n,b_1,\cdots,b_n" /></span><script type='math/tex'>a_1,a_2,\cdots,a_n,b_1,\cdots,b_n</script>，如何用<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_7ba55e7c64a9405a0b39a1107e90ca94.gif' style='vertical-align: middle; border: none; ' class='tex' alt="O(n)" /></span><script type='math/tex'>O(n)</script>的时间，<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_5e079a28737d5dd019a3b8f6133ee55e.gif' style='vertical-align: middle; border: none; ' class='tex' alt="O(1)" /></span><script type='math/tex'>O(1)</script>的空间，将这个序列顺序改为<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_d8523d1d0596a2a4106b0177db60807a.gif' style='vertical-align: middle; border: none; ' class='tex' alt="a_1,b_1,\cdots,a_n,b_n" /></span><script type='math/tex'>a_1,b_1,\cdots,a_n,b_n</script>。</p>
</blockquote>
<p><a href="http://zhiqiang.org/blog/science/computer-science/an-algorithm-face-interviews-question-test.html">那一次讨论</a>我们翻出了问题的来源，一篇长达12页的论文<a href="http://webhome.cs.uvic.ca/~jellis/Publications/shuffle.ps">Computing the Cycles in the Perfect Shuffle Permutation</a>，算法那是非常的复杂，我估计贴出来都没几个人仔细看。</p>
<p>这一次，Xie Xie（没错，又是他 <img src='http://zhiqiang.org/blog/wp-includes/images/smilies/smile.gif' alt=':)' class='wp-smiley' /> ）翻出了Art of Computer Programming, Volume 3上的一个难度为40分的Merge Sort习题：</p>
<blockquote><p>已知数列<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_7ad9ebc8e2af92fd300bda645d389cde.gif' style='vertical-align: middle; border: none; ' class='tex' alt="x_1\leq x_2\leq \cdots x_M, x_{M+1}\leq x_{M+2}\leq\cdots\leq x_n" /></span><script type='math/tex'>x_1\leq x_2\leq \cdots x_M, x_{M+1}\leq x_{M+2}\leq\cdots\leq x_n</script>，设计算法使得在线性时间，常数空间实现归并，也就是将原数组排序。</p>
</blockquote>
<p>而Perfect Shuffle问题是可以规约到这个Merge Sort问题的：</p>
<blockquote><pre>mergeSort(x[1...2n]); <span style="color: #008000">// if this function solve Merge Sort problem</span>
perfectShuffle(x[1...2n]): <span style="color: #008000">// then this solve Perfect Shuffle problem</span>
     m &lt;- <span style="color: #0000ff">max</span>(x[1...2n])+1;
     x[i] &lt;- x[i]+(2i-1)m,
     x[i+n] &lt;- x[i+n] + 2im
     mergeSort(x[1...2n])
     x[i] &lt;- x[i]%m</pre>
</blockquote>
<p>原来我还不相信这个问题会是一个面试题。现在我信了。因为那个归并排序的算法还是有些牛人会知道的。</p>
<p>很好很强大。</p>
<p>&nbsp;</p>
<p>另注：从2006年4月1号愚人节<a href="http://zhiqiang.org/blog/memopad/hello-world.html">开始</a>，阅微堂成立两周年了。</p>
<p>过去一年，阅微堂共发表了201篇文章，其中包括Liu Tao先生的<a href="http://zhiqiang.org/blog/author/liutao">19篇文章</a>，sog white的17篇文章，以及一些授权转载的网友原创作品。共3389条留言。</p>
<p>感谢大家的关注和对阅微堂的支持。</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/science/computer-science/an-algorithm-face-interviews-question-test.html">一个算法面试题 &#038; 面试题库</a></li><li><a href="http://zhiqiang.org/blog/memopad/reading-a-micro-appear-anniversary.html">阅微堂一周年</a></li><li><a href="http://zhiqiang.org/blog/science/game-two-hats.html">帽子游戏二</a></li><li><a href="http://zhiqiang.org/blog/science/googles-crazy-face-questions.html">Google的疯狂面试题</a></li><li><a href="http://zhiqiang.org/blog/it/emc-2008-10-writing-test.html">2008年10月EMC笔试</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/163-written-test-problems.html">网易笔试题</a></li><li><a href="http://zhiqiang.org/blog/science/worldquant-written-test-2007.html">WorldQuant的笔试题</a></li><li><a href="http://zhiqiang.org/blog/science/a-brain-teaser-microsoft.html">毛毛虫爬棍子面试题</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/inverse-square-root-algorithm-analysis.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/another-perfect-shuffle-algorithm.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html#comments">21 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>阅微堂一周年</title>
		<link>http://zhiqiang.org/blog/memopad/reading-a-micro-appear-anniversary.html</link>
		<comments>http://zhiqiang.org/blog/memopad/reading-a-micro-appear-anniversary.html#comments</comments>
		<pubDate>Sun, 01 Apr 2007 11:41:14 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[记事本]]></category>
		<category><![CDATA[memo]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/554.html</guid>
		<description><![CDATA[博客 » 记事本 » memo » 从去年4月1号愚人节开始，阅微堂成立一周年了。 过去一年，阅微堂共发表了226篇文章，其中包括Liu Tao先生的21篇文章，sog white的50篇文章，以及一些授权转载的网友原创作品。共3168条留言。 感谢大家的关注和对阅微堂的支持。 [tags]memo[/tags] 相关文章Perfect Shuffle的算法 &#169; zhiqiang for 阅微堂, 2007. &#124; &#38142;&#25509; &#124; 9 &#26465;&#35780;&#35770;]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/memopad">记事本</a> » <a href='http://zhiqiang.org/blog/tag/memo'>memo</a>  » </p><p>从去年4月1号愚人节<a href="http://zhiqiang.org/blog/memopad/hello-world.html">开始</a>，阅微堂成立一周年了。</p>
<p>过去一年，阅微堂共发表了226篇文章，其中包括Liu Tao先生的<a href="http://zhiqiang.org/blog/author/liutao">21篇文章</a>，sog white的50篇文章，以及一些授权转载的网友原创作品。共3168条留言。</p>
<p>感谢大家的关注和对阅微堂的支持。</p>
<p>[tags]memo[/tags]</p>
<div><h4>相关文章</h4><ul><li><a href="http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html">Perfect Shuffle的算法</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/memopad/reading-a-micro-appear-anniversary.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/memopad/reading-a-micro-appear-anniversary.html#comments">9 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/memopad/reading-a-micro-appear-anniversary.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

