A weak heap is a priority queue that supports the operations construct, minimum, insert, and extract-min. To store n elements, it uses an array of n elements and an array of n bits. In this paper we study different possibilities for optimizing construct and insert such that minimum and extract-min are not made slower. We provide a catalogue of algorithms that optimize the standard algorithms in various ways. As the optimization criteria, we consider the worst-case running time, the number of instructions, branch mispredictions, cache misses, element comparisons, and element moves. Our contributions are summarized as follows:1.The standard algorithm for construct runs in O(n) worst-case time and performs n-1 element comparisons. Our improved algorithms reduce the number of instructions, the number of branch mispredictions, the number of element moves, and the number of cache misses. 2(a)Even though the worst-case running time of the standard insert algorithm is logarithmic, we show that-in contrast to binary heaps-n repeated insert operations require at most 3.5n+O(lg^2n) element comparisons. 2(b)We improve a recent result of ours, in which we achieve O(1) amortized time per insertion, to guarantee O(1) worst-case time per insertion. After the deamortization, minimum still takes O(1) worst-case time and involves no element comparisons, and extract-min takes O(lgn) worst-case time and involves at most lgn+O(1) element comparisons. This constant-factor optimality concerning the number of element comparisons has previously been achieved only by pointer-based multipartite priority queues. We have implemented most of the proposed algorithms and tested their practical behaviour. Interestingly, for integer data, reducing the number of branch mispredictions turned out to be an effective optimization in our experiments.
[1]
Ronald L. Rivest,et al.
Introduction to Algorithms
,
1990
.
[2]
Ingo Wegener,et al.
On the Performance of WEAK-HEAPSORT
,
2000,
STACS.
[3]
Jyrki Katajainen,et al.
Performance engineering case study: heap construction
,
1999,
JEAL.
[4]
Ronald L. Rivest,et al.
Introduction to Algorithms, third edition
,
2009
.
[5]
Ronald D. Dutton,et al.
Weak-heap sort
,
1993,
BIT.
[6]
Ingo Wegener.
BOTTOM-UP-HEAPSORT, a New Variant of HEAPSORT, Beating, on an Average, QUICKSORT (if n is not Very Small)
,
1993,
Theor. Comput. Sci..
[7]
Amr Elmasry,et al.
The weak-heap data structure: Variants and applications
,
2012,
J. Discrete Algorithms.
[8]
Stefan Edelkamp,et al.
Implementing HEAPSORT with (n logn - 0.9n) and QUICKSORT with (n logn + 0.2n) comparisons
,
2002,
JEAL.
[9]
Ronald L. Rivest,et al.
Introduction to Algorithms, 3rd Edition
,
2009
.
[10]
Amr Elmasry,et al.
Multipartite priority queues
,
2008,
TALG.
[11]
Amr Elmasry,et al.
In-place Heap Construction with Optimized Comparisons, Moves, and Cache Misses
,
2012,
MFCS.
[12]
Mikkel Thorup,et al.
Black box for constant-time insertion in priority queues (note)
,
2005,
TALG.
[13]
Jean Vuillemin,et al.
A data structure for manipulating priority queues
,
1978,
CACM.
[14]
Stefan Edelkamp,et al.
Policy-Based Benchmarking of Weak Heaps and Their Relatives,
,
2010,
SEA.