Worst-Case Analysis of Heapsort, Exactly

被引:0
作者
Suchenek, Marek A. [1 ]
机构
[1] Calif State Univ Dominguez Hills, Dept Comp Sci, 1000 E Victoria St, Carson, CA 90747 USA
关键词
heap; heapsort; sorting; sum of digits; worst case;
D O I
10.1093/comjnl/bxad007
中图分类号
TP3 [计算技术、计算机技术];
学科分类号
0812 ;
摘要
This paper completes analysis of the worst-case running time of $ {\tt{Heapsort}}$ measured by the number of comparisons of keys performed while sorting. A derivation of an exact formula for the maximum number of comparisons of keys performed by $ {\tt{Heapsort}} $ on any array of size $ N \geq 2 $ is presented. It is equal to $$ \begin{align}& \nonumber 2(N-1)\lceil \lg N \rceil - 2 <^>{\lceil \lg N \rceil +1} - 2 s_2(N) - e_2(N) + \min (\lceil \lg N \rceil, 3) + 5 + c, \end{align} $$ where $s_2(N)$ is the sum of digits of the binary representation of $N$, $e_2(N)$ is the exponent of $2$ in the $N$'s prime factorization and $ c $ is a binary function on the set of positive integers defined by $$ \begin{align}& \nonumber c = \left\{ \begin{array}{@{}ll} 1 \text{ if} \; N \leq 2 <^>{\lceil \lg N \rceil} - 4 \\[4pt] 0 \text{ otherwise}. \end{array} \right. \end{align} $$ The above formula allows for deciding, in $ O(N \log N) $ time, if any given $ N $-element array is a worst-case array for $ {\tt{Heapsort}} $. Its proof yields an algorithm for construction, in $ O(N \log N) $ time, of worst-case arrays of arbitrary sizes $ N \geq 2 $ for $ {\tt{Heapsort}} $.
引用
收藏
页码:812 / 824
页数:13
相关论文
共 11 条
  • [1] Cormen T.H., 2009, Introduction to Algorithms, V3
  • [2] Flajolet P, 2009, ANALYTIC COMBINATORICS, P1, DOI 10.1017/CBO9780511801655
  • [3] ALGORITHM-245 - TREESORT 3 [M1]
    FLOYD, RW
    [J]. COMMUNICATIONS OF THE ACM, 1964, 7 (12) : 701 - 701
  • [4] Knuth Donald E, 1997, Seminumerical Algorithms, V2
  • [5] Kruskal C.P., 1979, WORST CASE ANAL HEAP
  • [6] THE ANALYSIS OF HEAPSORT
    SCHAFFER, R
    SEDGEWICK, R
    [J]. JOURNAL OF ALGORITHMS, 1993, 15 (01) : 76 - 100
  • [7] Suchenek M.A., 2014, HEREDITARY WORST CAS
  • [8] Suchenek M.A., 2015, ARXIV, DOI DOI 10.48550/ARXIV.1504.01459
  • [9] Elementary Yet Precise Worst-Case Analysis of Floyd's Heap-Construction Program
    Suchenek, Marek A.
    [J]. FUNDAMENTA INFORMATICAE, 2012, 120 (01) : 75 - 92
  • [10] WILLIAMS JWJ, 1964, COMMUN ACM, V7, P347