The worst-case behavior of the heap-construction phase of Heapsort escaped mathematically precise characterization by a closed-form formula for almost five decades. This paper offers a proof that the exact number of comparisons of keys performed in the worst case during construction of a heap of size N is: 2N − 2s 2 (N) − e 2 (N), where s 2 (N) is the sum of all digits of the binary representation of N and e 2 (N) is the exponent of 2 in the prime factorization of N. It allows for derivation of this best-known upper bound on the number of comparisons of Heapsort: (2N − 1)$\lceil$lgN$\rceil$ − 2 $\lceil$lgN$\rceil$+1 − 2s 2 (N) − e 2 (N) + 5.
End of preview. The entire article is 18 pages. Rent for Free