We use cookies to improve your experience with our site.

最坏情况下用nlog n ? 0.788928n 次比较的改进堆排序算法

An Improved HEAPSORT Algorithm with n log n - 0.788928n Comparisons in the Worst Case

  • 摘要: 按照某个线性序(例如,数的小于关系)对一些对象进行排序是用计算机处理信息时经常要做的一项基本工作。排序算法的效率在许多软件的设计中占有非常重要的地位。国内外计算机科学家对排序算法的研究经久不衰,至今仍是一个热门的研究课题。在一般情况下,排序问题的输入是n 个数a1,a2,…,an的一个序列,要设计一个有效的排序算法,产生输入序列的一个重排,使序列元素按从小到大的顺序排列。输入序列通常是一个有n个元素的数组,当然也可以用其它形式来表示输入,如链表等。对排序算法计算时间的分析可以遵循若干种不同的准则,通常以排序过程所需要的算法步数作为度量,有时也以排序过程中所作的键值比较次数作为度量。特别是当一次键值比较需要较长时间,例如,当键是较长的字符串时,常以键值比较次数作为排序算法计算时间复杂性的度量。本文所研究的是基于比较的排序算法。本文提出了一个在最坏情况下用nlog n ? 0.788928n 次比较的改进堆排序算法。在平均情况下,该算法比目前最好的快速排序算法所需时间有较大改进。算法的基本思想是在每个结点处只作1 次比较找到叶结点,放松了根结点1 次到位的要求。因此需要较少的比较次数。对于提出的新算法,本文从理论和实验2 个方面对算法的性能进行了较深入的分析。从理论上严格证明了在最坏情况下算法的计算时间复杂度为nlog n ? 0.788928n 。对算法的实验分析表明,算法实际需要的计算时间约为nlog n ? n ,这比目前提出的排序算法优越。如果将新的排序算法用于软件设计,无疑将大大提高软件的效率和性能。

     

    Abstract: A new variant of HEAPSORT is presented in this paper. The algorithm is not an internalsorting algorithm in the strong sense, since extra storage for nintegers is necessary. The basic idea of the new algorithm is similar tothe classical sorting algorithm HEAPSORT, but the algorithm rebuilds theheap in another way. The basic idea of the new algorithm is it uses onlyone comparison at each node. The new algorithm shift walks down a path inthe heap until a leaf is reached. The request of placing the element inthe root immediately to its destination is relaxed. The new algorithmrequires about n \log n-0.788928n comparisons in the worst case andn\log n-n comparisons on the average which is only about 0.4n morethan necessary. It beats on average even the clever variants ofQUICKSORT, if n is not very small. The difference between the worstcase and the best case indicates that there is still room forimprovement of the new algorithm by constructing heap more carefully.

     

/

返回文章
返回