The second smallest

算法导论书上有个练习,让证明n个元素的第2个最小的元素可以用n + ceil(lg n) - 2次比较找出来,给的提示只是:把最小的也找出来。

我想了好久,终于出来了。思路是:n-1次比较找出最小,然后再用ceil(lg n)-1次比较就找到第2个最小。具体见这一页

This entry was posted on Monday, January 8th, 2007 at 11:56 pm and is filed under Algorithm. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Comments »

Comment by Zhang
2007-01-09 09:47:46

O(n)就能做的

 
Comment by Zhang
2007-01-09 09:48:12

oo,弄错了

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)

Please copy the string 67VBZM to the field below: