<?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%9f%a9%e9%98%b5/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/median-algorithm-of-ordered-matrix.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/median-algorithm-of-ordered-matrix.html#comments</comments>
		<pubDate>Mon, 09 Jun 2008 03:23:03 +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/median-algorithm-of-ordered-matrix.html</guid>
		<description><![CDATA[博客 » 计算机科学 » 算法 » 给定的实数矩阵，每行和每列都是递增的，求这个数的中位数。 使用类似Tarjan的线性中位数的方法，每次找每列中位数，然后找中位数的中位数，之后可以删除前一半列的上半部分或者后一半列的下半部分，这样可以实现复杂性。 但是这个问题是有的算法的，在Top Language Google Group的Obtuse Sword的指点下，找到了这个问题的原始论文：Generalized Selecti...]]></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>给定<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_607acaa73c762411b20745149a11e90b.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="n\times n" /></span><script type='math/tex'>n\times n</script>的实数矩阵，每行和每列都是递增的，求这<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_6595d679e306a127a3fe53268bcaddb2.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="n^2" /></span><script type='math/tex'>n^2</script>个数的中位数。</p>
<p>使用类似Tarjan的线性中位数的方法，每次找每列中位数，然后找中位数的中位数，之后可以删除前一半列的上半部分或者后一半列的下半部分，这样可以实现复杂性<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_f7abf0190aa2a37a63aff83e6af0da07.gif' style='vertical-align: middle; border: none; ' class='tex' alt="O(n\log^2n)" /></span><script type='math/tex'>O(n\log^2n)</script>。</p>
<p>但是这个问题是有<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>的算法的，在<a href="http://groups.google.com/group/pongba" target="_blank">Top Language Google Group</a>的<a href="http://groups.google.com/group/pongba/msg/c2e0e047c127c2b7" target="_blank">Obtuse Sword的指点</a>下，找到了这个问题的原始论文：<a href="http://epubs.siam.org/error/cookies.jsp?url=http%3a//epubs.siam.org/sicomp/resource/1/smjcat/v13/i1/p14_s1" target="_blank">Generalized Selection and Ranking: Sorted Matrices</a>。事实上这篇论文证明了更强的结论：</p>
<blockquote><p>对于一个<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_252d3754c0db62a55b9e25c870a524a5.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="n\times m" /></span><script type='math/tex'>n\times m</script>(<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_a9c6d1101125bbf3954a5821e556cced.gif' style='vertical-align: middle; border: none; ' class='tex' alt="n\leq m" /></span><script type='math/tex'>n\leq m</script>)的矩阵，若每行和每列都是递增的，则可以在<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_2a5a84e2d2b3faed163740163b33fb7b.gif' style='vertical-align: middle; border: none; ' class='tex' alt="O(n\log2m/n)" /></span><script type='math/tex'>O(n\log2m/n)</script>找到第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_8ce4b16b22b58894aa86c421e8759df3.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="k" /></span><script type='math/tex'>k</script>大的数。</p>
</blockquote>
<p>算法的基本思路是将矩阵依次对半划分成更小的子矩阵，然后删除不可能包含所求中位数的子矩阵。通过对每次划分后子矩阵个数的估计，发现此算法时间复杂度为<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_2a5a84e2d2b3faed163740163b33fb7b.gif' style='vertical-align: middle; border: none; ' class='tex' alt="O(n\log2m/n)" /></span><script type='math/tex'>O(n\log2m/n)</script>。</p>
<p>使用同样的技巧，可以证明更更强的结论(这个算法具体过程就没细看了):</p>
<blockquote><p>一堆<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_677228ad87e3811d7e2772f3b3897674.gif' style='vertical-align: middle; border: none; ' class='tex' alt="n_i\times m_i" /></span><script type='math/tex'>n_i\times m_i</script>(<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_29e47411160e0bc1091c57173a55b0d3.gif' style='vertical-align: middle; border: none; ' class='tex' alt="n_i\leq m_i" /></span><script type='math/tex'>n_i\leq m_i</script>)的矩阵，若每个矩阵的每行和每列都是递增的，则selection problem（即找第<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_8ce4b16b22b58894aa86c421e8759df3.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="k" /></span><script type='math/tex'>k</script>大的数）的时间复杂度为<span class='MathJax_Preview'><img src='http://zhiqiang.org/blog/wp-content/plugins/latex/cache/tex_12294fa07ca565682ae047f236a83874.gif' style='vertical-align: middle; border: none; ' class='tex' alt="O(\sum n_i\log2m_i/n_i)" /></span><script type='math/tex'>O(\sum n_i\log2m_i/n_i)</script>。</p>
</blockquote>
<div><h4>相关文章</h4><ul><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/programs-depend-on-date-struct-not-algorithm.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/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/3-color-a-simple-graph.html">一个简单图的三染色算法问题</a></li><li><a href="http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.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/median-algorithm-of-ordered-matrix.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/median-algorithm-of-ordered-matrix.html#comments">4 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/median-algorithm-of-ordered-matrix.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

