(R.W.Floyd) During the selection phase of heapsort, the key K tends to
be quite small, so that nearly all the comparisons in step H6 find
K<K_j. Show how to modify the algorithm so that K is not compared with
K_j in the main loop of the computation, thereby nearly cutting the
average number of comparisons in half.
答案里面的方法和DMK的方法是一样的。(我觉得DMK是看了这个论文或者TAoCP的) 这里说 by half,就正好和快排差不多了。
2012年11月6日[回复]()[顶]()[转发]()[举报]()
* [![ouqi]()](http://weibo.com/xianqings "ouqi")
[ouqi](http://weibo.com/xianqings)
同不明白这一块:
然而,快排的第二次比较就不那么高明了:我们不妨令轴元素为pivot,第一次比较结果是a1<pivot,那么可以证明第二次比较a2也小于pivot的可能性是2/3!这容易证明:如果a2>pivot的话,那么a1,a2,pivot这三个元素之间的关系就完全确定了——a1<pivot<a2,剩下来的元素排列的可能性我们不妨记为P(不需要具体算出来)。而如果a2<pivot呢?那么a1和a2的关系就仍然是不确定的,也就是说,这个分支里面含有两种情况:a1<a2<pivot,以及a2<a1<pivot。对于其中任一种情况,剩下的元素排列的可能性都是P,于是这个分支里面剩下的排列可能性就是2P。所以当a2<pivot的时候,还剩下2/3的可能性需要排查。
我的疑惑在于,第一次的a2是什么,为什么要把第二次的排序和第一次的排序相关联?
不明白您定义的第二次排序是什么,我以为的第二次排序是对第一次的起始位置到第一次的pivot之间的数字的排序,那么第二次的privot又是重新选定的。也就是说在第一次排序之后,任何一个值跟第一次的privot的大小关系都是确定了的,要么比他大 要么比他小。那您说a2是什么?
4月10日[回复]()[顶]()[转发]()[举报]()
* [![ナイキ 通販]()](http://www.abcsnk.com/ "ナイキ 通販")
[ナイキ 通販](http://www.abcsnk.com/)
searching is another thing no doubt you like to accomplish (specially me), when i don't recognize how but searching is one particular activity which offers us eminence delight and relaxation whenever we are generally tired as well as frustrated as well as irritated, but while using ever raising targets along with office update they have became next to impossible for us to determine some time for it to hang out with his friends and enjoy that period while rooming around for the streets involving market.
But even as we always say there's [http://www.abcsnk.com/adidas-スパイクサッカー-アディピュア-11pro-c-22_23_29.html](http://www.abcsnk.com/adidas-スパイクサッカー-アディピュア-11pro-c-22_23_29.html) アディピュア11pro a option for just about every problem along with situation on the [http:///www.sportrakuten.com](http:/www.sportrakuten.com) サングラス通販 globe, all you want to do is seek out that option with [http://www.sportrakuten.com/categories/1369471366-179.html](http://www.sportrakuten.com/categories/1369471366-179.html) レイバン サングラス 'something different' perspective. And which is the very reason we invented a many new method involving shopping which in turn know while online searching method. But staying this strategy new types of quarries that happen to be there inside mind of folks related on the same and were here to unravel those themselves.
But today you'll find thousands involving products that is purchased via an web shop starting coming from a bugger to your flat in fact it is impossible for individuals to cover hundreds of in one particular discussion themselves therefore today we'll be only talking over facts pertains to [http://www.abcsnk.com](http://www.abcsnk.com/) ナイキ 通販 online searching of sneakers for adult men.
Buying some your favourite Adidas [http://www.abcsnk.com/adidas-スパイクサッカー-プレデター-アディダス-11-c-22_23_25.html](http://www.abcsnk.com/adidas-スパイクサッカー-プレデター-アディダス-11-c-22_23_25.html) adidas プレデター sneakers from these websites is just about the easiest thing on the [http:///www.sportrakuten.com/categories/1369471516-183.html](http:/www.sportrakuten.com/categories/1369471516-183.html) レイバン(RAY BAN) globe, but to generate it truly easy you've got to keep up few in the things as well as points that happen to be listed down below.
6月19日[回复]()[顶]()[转发]()[举报]()
[1]()[]()
社交帐号登录:
* [微博](http://pongba.duoshuo.com/login/weibo/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [QQ](http://pongba.duoshuo.com/login/qq/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [人人](http://pongba.duoshuo.com/login/renren/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [豆瓣](http://pongba.duoshuo.com/login/douban/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [更多»]()
* [开心](http://pongba.duoshuo.com/login/kaixin/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [网易](http://pongba.duoshuo.com/login/netease/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [搜狐](http://pongba.duoshuo.com/login/sohu/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [百度](http://pongba.duoshuo.com/login/baidu/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
* [谷歌](http://pongba.duoshuo.com/login/google/?sso=1&redirect_uri=http%3A%2F%2Fmindhacks.cn%2Fwp-login.php%3Faction%3Dduoshuo_login&redirect_to%3Dhttp%3A%2F%2Fmindhacks.cn%2F2008%2F06%2F13%2Fwhy-is-quicksort-so-quick%2F)
[![]()]()
发布
[]( "插入表情")
[刘未鹏 | Mind Hacks正在使用多说](http://duoshuo.com/)
1. chaonin on [February 17, 2009 at 10:34 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-93) said:
@@之前就在你的卢浮宫看到了,写的直白明了!
小弟学的是编码,呵呵。
Mackay的那本书重点是介绍编码的,具体的说是纠错码的。编码理论的重要基础是信息论。
他对这些问题的分析不是专门要来分析这写问题的,而只是用信息论的方法来解释这些现象。
1. [帅得不敢出门](http://stupidpig.cublog.cn/) on [March 23, 2009 at 8:46 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-292) said:
受益良多
每每看到一些精妙的解法(算法),都想拍手称快.
1. [conan](http://www.cloved.cn/) on [May 11, 2009 at 9:43 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-407) said:
关注toplanguage很久了.只是一直不敢在上面留言,看上面的聊天就感觉自己是沧海一粟.今天看到一篇.可能你是幸运的吧.我大概算了下,你应该是和我同届的.不过我比你小一岁.马上就毕业两年了.研究生们也快毕业了….回忆这些日子,感觉偏离了自己的目标,也感觉工作后并没有自己希望的成长着.一直觉得学校的东西很迂腐,什么都需要自己去学习.曾经也深深相信自己能好好成长起来.只是,到了今天,不知道自己是否还跟着大家的脚步….
1. metal-fan on [October 15, 2009 at 9:13 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-616) said:
写的太棒了~深入本质~受益匪浅!!!
1. raymond on [December 25, 2009 at 10:38 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-709) said:
这是最大熵原则的几个例子,即保留最大的不确定性,因为这样才能保留最大的信息。生活中很多问题都可以归结为一些简单的法则,而在实际处理问题的时候,这些简单的法则会被以各种各样的形式掩盖,从而让我们失去探索的机会。博主是个有心人啊
1. bigining on [April 24, 2010 at 6:10 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-888) said:
在说到12个的例子时,第二次称时:“这是一个完美的三分。然后对每个分支构造第二次称法,这里你只要稍加演算就可以发现,分支1上的第二次称法,即“1、2、6对3、4、5”这种称法,天平输出三种结果的可能性是均等的(严格来说是几乎均等)。”,但是这样好像是找不出那个不同的球的。不知道1、2、6对3、4、5之后要怎么进行判断?(可以假设1、2、6比3、4、5重,然后只能说明1、 2较重或5较轻,然后第三次要怎么进行?)
* Ted on [November 28, 2011 at 3:30 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-18264) said:
晕,你都说了“然后只能说明1、 2较重或5较轻”,这还不明显,再把1,2分别放2边,哪个重,哪个就是,否则就是平衡,那5就是目标。
* rrison on [May 6, 2010 at 11:26 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-904) said:
离散数学里的博弈树
* [dell latitude d620 laptop battery](http://www.usbphoneworld.com/lbded6620.html) on [June 13, 2010 at 10:56 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-934) said:
非常感谢。受益良多。
*
Pingback: [数学之美番外篇:快排为什么那样快 | 天道酬勤](http://www.iskycloud.com/blog/algorithm/52.html)
* kmplayer on [December 16, 2010 at 3:25 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-11214) said:
“那么可以证明第二次比较a2也小于pivot的可能性是2/3!”
”a3<pivot的概率将会是3/4!“
这两个地方的”叹号“很容易误解为”阶层“
* hit_alex on [December 26, 2010 at 5:15 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-11319) said:
把这西抽象出来确实也挺有意思的。另外,我注意到标题:**鸡排为什么又那么快呢?**中“鸡排”是不是写错了?莫非是作者故意为之?
* [Miller](http://www.lisher.tk/) on [February 14, 2011 at 10:23 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-12358) said:
4、4称了之后不管哪种情况(分支),剩下来的可能性总是》 8 《种吧
*
Pingback: [知其所以然(续) - 东莞律师网](http://www.lawyer888.com/?p=122)
*
Pingback: [知其所以然(续) | w3er](http://w3er.com/%e6%9c%aa%e5%88%86%e7%b1%bb/%e7%9f%a5%e5%85%b6%e6%89%80%e4%bb%a5%e7%84%b6%ef%bc%88%e7%bb%ad%ef%bc%89/)
*
Pingback: [知其所以然(三)——为什么算法这么难?](http://mindhacks.cn/2011/07/10/the-importance-of-knowing-why-part3/)
*
Pingback: [推荐读书《暗时间》](http://www.whoisnerd.com/2011/07/31/%e6%8e%a8%e8%8d%90%e8%af%bb%e4%b9%a6%e3%80%8a%e6%9a%97%e6%97%b6%e9%97%b4%e3%80%8b/)
*
Pingback: [转:为什么算法这么难? | South♂楠个人博客](http://southmagic.sinaapp.com/?p=18)
*
Pingback: [知其所以然(续) | 风的天地](http://blog69.tk/?p=540)
*
Pingback: [知其所以然(三):为什么算法这么难? | 风的天地](http://blog69.tk/?p=114)
* wosunziwuwan on [November 27, 2011 at 9:55 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-18259) said:
“那么可以证明第二次比较a2也小于pivot的可能性是2/3″这句话有问题吧,可能性应该还是1/2吧?因为只是a2和pivot相对次序的比较,和a1无关,是一次独立的比较。这和取排问题不同,确定了2张牌后,第3张牌只有从剩下的牌中去取
* [yeasy](http://yeasy.blogspot.com/) on [December 15, 2011 at 4:23 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-18653) said:
更为本质一些,我觉得跟最大熵原理有些关系。
参考http://yeasy.blogspot.com/2011/11/blog-post.html
*
Pingback: [罗青-技术博客 | [re]趣谈二分法](http://tsingroo.sinaapp.com/?p=302)
*
Pingback: [趣题:天平找假币 - Aikilis' Blog](http://aikilis.tk/1398)
*
Pingback: [快排_quicksort() - C++](http://cblog.lylzone.info/2012/03/6/quicksort.html)
* LittleJ on [March 19, 2012 at 6:12 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-20448) said:
“第一次比较结果是a1<pivot,那么可以证明第二次比较a2也小于pivot的可能性是2/3!"这里我也不是很明白。这里指的第一次第二次都是相对于快排的一次排序来说的吧?那么第一次将a1和pivot比较,大或者小的概率是相等的这里没有问题。为什么第二次比较a2要“也”小于pivot呢?我的意思就是第一次比较和第二次比较之间有什么关联?这里我没有看明白,能不能解释一下呢?谢谢:)
*
Pingback: [知其所以然(三):为什么算法这么难? | 吃杂烩](http://blog.chiapp.com/html/2012-08-09/4159.html)
*
Pingback: [所有排序总结(内排序)(续)——基于比较排序下界 | 编程·早晨](http://code.zc4u.com/articles/5362.html)
*
Pingback: [孙吾饭的游乐场 | 暗时间](http://patdelphi.com/wordpress/?p=508)
* [透明的沙子](http://www.douban.com/people/49902334/) on [September 3, 2012 at 8:51 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31818) said:
“然而,快排的第二次比较就不那么高明了:我们不妨令轴元素为pivot,第一次比较结果是a1pivot的话,那么a1,a2,pivot这三个元素之间的关系就完全确定了——a1
* [透明的沙子](http://www.douban.com/people/49902334/) on [September 3, 2012 at 8:53 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31819) said:
看起来很多人不理解这个,反复想不明白,坐等解答啊
* [滔要考研](http://weibo.com/1742521405) on [September 7, 2012 at 1:06 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31827) said:
关于快排的部分,其实本质是指轴元素如果选取的不够“中间”,会导致第一次排序后左右不均,从而导致较差的效率表现。刘大牛从缩减可能性这个角度出发,让人耳目一新。受教了。
* simple on [September 21, 2012 at 11:34 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31875) said:
以6个球的例子来说,这个策略的“答案”是随着剩下的可能性(或者说剩下的球)的数量而发生变化的,比如,当球剩下2个时,那么天平的输出结果只可能有两种:左或右倾。因此,这时候应该是以以2去平分剩下的可能性。
* simple on [September 22, 2012 at 1:35 am](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31876) said:
鸡排之所以快,我觉得还可以用另一种说法(以13张牌的例子为例):第i张牌确定位置后,放第i+1张牌时,桌上剩下的位置还有 13-i 个,即放牌的可能性为13-i种,然后,摸牌再看是什么点数就相当于公布答案,而这个答案刚好也是有 13-i 种,即,13-i种答案把13-i种可能性平均分为了13-i/13-i = 1种,最后得到鸡排需要的时间复杂度为O(1)
* imgen on [September 29, 2012 at 5:45 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31903) said:
关于称球问题,我正是用了信息论的方法为指引,三分而称球,而且我也给出了推广到N的解法,从中获得了很多乐趣和满足。不过那是在大学时代了,久远了
* [icrt_](http://weibo.com/2177249280) on [October 10, 2012 at 9:03 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31922) said:
真心佩服了。之前觉得称球问题没有什么,看这文章才知道原来有这么多的东西!
* [_小毛童鞋_](http://weibo.com/1238983263) on [October 16, 2012 at 6:25 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-31942) said:
高爷爷是谁?
* [鸡翅呀鸡翅](http://weibo.com/brightown) on [November 6, 2012 at 3:21 pm](http://mindhacks.cn/2008/06/13/why-is-quicksort-so-quick/comment-page-1/#comment-32004) said:
哇高爷爷果然是神人也,查了一下73年v3的第一版就有神论~~~膜拜orz
searching is another thing no doubt you like to accomplish (specially me), when i don’t recognize how but searching is one particular activity which offers us eminence delight and relaxation whenever we are generally tired as well as frustrated as well as irritated, but while using ever raising targets along with office update they have became next to impossible for us to determine some time for it to hang out with his friends and enjoy that period while rooming around for the streets involving market.
But even as we always say there’s http://www.abcsnk.com/adidas-スパイクサッカー-アディピュア-11pro-c-22_23_29.html アディピュア11pro a option for just about every problem along with situation on the http:///www.sportrakuten.com サングラス通販 globe, all you want to do is seek out that option with http://www.sportrakuten.com/categories/1369471366-179.html レイバン サングラス ‘something different’ perspective. And which is the very reason we invented a many new method involving shopping which in turn know while online searching method. But staying this strategy new types of quarries that happen to be there inside mind of folks related on the same and were here to unravel those themselves.
But today you’ll find thousands involving products that is purchased via an web shop starting coming from a bugger to your flat in fact it is impossible for individuals to cover hundreds of in one particular discussion themselves therefore today we’ll be only talking over facts pertains to http://www.abcsnk.com ナイキ 通販 online searching of sneakers for adult men.