Optimizing Binary Heaps

A priority queue—a data structure supporting, inter alia, the operations minimum (top), insert (push), and extract-min (pop)—is said to operate in-place if it uses O(1) extra space in addition to the n elements stored at the beginning of an array. Prior to this work, no in-place priority queue was known to provide worst-case guarantees on the number of element comparisons that are optimal up to additive constant terms for both insert and extract-min. In particular, for the standard implementation of binary heaps, insert and extract-min operate in logarithmic time while involving at most dlg ne and 2 lg n [could possibly be reduced to lg lg n + O(1) and lg n + log∗ n + O(1)] element comparisons, respectively. In this paper we propose a variant of a binary heap that operates in-place, executes minimum and insert in O(1) worst-case time, and extract-min in O(lg n) worst-case time while involving at c © 2017 Springer Science+Business Media, New York. This is the authors’ version of the work. The final publication is available at Springer via http: //dx.doi.org/10.1007/s00224-017-9760-2 A preliminary version of this paper entitled “An in-place priority queue with O(1) time for push and lgn + O(1) comparisons for pop” [19] was presented at the 10th International Computer Science Symposium in Russia held in Listvyanka in July 2015. Stefan Edelkamp Faculty 3—Mathematics and Computer Science, University of Bremen, PO Box 330 440, 28334 Bremen, Germany E-mail: edelkamp@tzi.de Amr Elmasry Department of Computer Engineering and Systems, Alexandria University, Alexandria 21544, Egypt E-mail: elmasry@alexu.edu.eg Jyrki Katajainen Department of Computer Science, University of Copenhagen, Universitetsparken 5, 2100 Copenhagen East, Denmark E-mail: jyrki@di.ku.dk most lg n+O(1) element comparisons. These efficiencies surpass lower bounds known for binary heaps, thereby resolving a long-standing theoretical debate.

[1]  Gu Xunrang,et al.  Asymptotic Optimal HEAPSORT Algorithm , 1994, Theor. Comput. Sci..

[2]  Svante Carlsson A Variant of Heapsort with Almost Optimal Number of Comparisons , 1987, Inf. Process. Lett..

[3]  Yijie Han Deterministic sorting in O(nlog log n) time and linear space , 2002, STOC '02.

[4]  Ingo Wegener A Simple Modification of Xunrang and Yuzhang's HEAPSORT Variant Improving its Complexity Significantly , 1993, Comput. J..

[5]  Mikkel Thorup,et al.  Black box for constant-time insertion in priority queues (note) , 2005, TALG.

[6]  Ronald D. Dutton,et al.  Weak-heap sort , 1993, BIT.

[7]  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..

[8]  Mark R. Brown,et al.  Implementation and Analysis of Binomial Queue Algorithms , 1978, SIAM J. Comput..

[9]  Amr Elmasry,et al.  Multipartite priority queues , 2008, TALG.

[10]  Jyrki Katajainen The Ultimate Heapsort , 1998, CATS.

[11]  Amr Elmasry,et al.  In-place Heap Construction with Optimized Comparisons, Moves, and Cache Misses , 2012, MFCS.

[12]  Gu Xunrang,et al.  A New HEAPSORT Algorithm and the Analysis of Its Complexity , 1990, Comput. J..

[13]  Amr Elmasry,et al.  Memory-Adjustable Navigation Piles with Applications to Sorting and Convex Hulls , 2015, ACM Trans. Algorithms.

[14]  Amr Elmasry,et al.  Strengthened Lazy Heaps: Surpassing the Lower Bounds for Binary Heaps , 2014, ArXiv.

[15]  Donald B. Johnson,et al.  Priority Queues with Update and Finding Minimum Spanning Trees , 1975, Inf. Process. Lett..

[16]  Christos Levcopoulos,et al.  Adaptive Heapsort , 1993, J. Algorithms.

[17]  Yuzhang Zhu,et al.  Optimal heapsort algorithm , 1996 .

[18]  Svante Carlsson,et al.  An Optimal Algorithm for Deleting the Root of a Heap , 1991, Inf. Process. Lett..

[19]  J. Ian Munro,et al.  An Implicit Binomial Queue with Constant Insertion Time , 1988, SWAT.

[20]  Peter van Emde Boas Thirty nine years of stratified trees , 2013 .

[21]  Amr Elmasry,et al.  Weak heaps engineered , 2013, J. Discrete Algorithms.

[22]  Yijie Han,et al.  Deterministic sorting inO(nlog logn) time and linear space , 2002, STOC 2002.

[23]  Amr Elmasry,et al.  The weak-heap data structure: Variants and applications , 2012, J. Discrete Algorithms.

[24]  Amr Elmasry,et al.  Two Skew-Binary Numeral Systems and One Application , 2011, Theory of Computing Systems.

[25]  Amr Elmasry,et al.  An In-Place Priority Queue with O(1) Time for Push and lg n + O ( 1 ) Comparisons for Pop , 2015, CSR.

[26]  Ingo Wegener The Worst Case Complexity of McDiarmid and Reed's Variant of Bottom-Up-Heap Sort is Less Than n log n + 1.1n , 1991, STACS.

[27]  Ronald L. Rivest,et al.  Introduction to Algorithms , 1990 .

[28]  Robert E. Tarjan,et al.  Relaxed heaps: an alternative to Fibonacci heaps with applications to parallel computation , 1988, CACM.

[29]  Jörg-Rüdiger Sack,et al.  A Characterization of Heaps and Its Applications , 1990, Inf. Comput..

[30]  Donald E. Knuth,et al.  The Art of Computer Programming, Volume I: Fundamental Algorithms, 2nd Edition , 1997 .

[31]  Donald E. Knuth,et al.  The art of computer programming: sorting and searching (volume 3) , 1973 .

[32]  Rudolf Fleischer,et al.  A tight lower bound for the worst case of Bottom-Up-Heapsort , 1994, Algorithmica.

[33]  Xiaodong Wang,et al.  A New Variant of In-Place Sort Algorithm , 2012 .

[34]  Colin McDiarmid,et al.  Average Case Analysis of Heap Building by Repeated Insertion , 1991, J. Algorithms.

[35]  Svante Carlsson,et al.  Heaps with Bits , 1996, Theor. Comput. Sci..

[36]  A. Harvey,et al.  THE POST-ORDER HEAP , 2004 .

[37]  Bruce A. Reed,et al.  Building Heaps Fast , 1989, J. Algorithms.

[38]  Timothy J. Purcell Sorting and searching , 2005, SIGGRAPH Courses.

[39]  Mikkel Thorup Equivalence between priority queues and sorting , 2007, JACM.

[40]  Alan M. Frieze,et al.  On the Best Case of Heapsort , 1996, J. Algorithms.

[41]  Mark H. Overmars,et al.  The Design of Dynamic Data Structures , 1987, Lecture Notes in Computer Science.

[42]  Gaston H. Gonnet,et al.  Heaps on Heaps , 1982, SIAM J. Comput..

[43]  X. Gu,et al.  Asymptotic optimal HEAPSORT algorithm , 1994 .

[44]  Gu Xunrang,et al.  Optimal Heapsort Algorithm , 1996, Theor. Comput. Sci..

[45]  Robert Sedgewick,et al.  The Analysis of Heapsort , 1993, J. Algorithms.

[46]  Jean Vuillemin,et al.  A data structure for manipulating priority queues , 1978, CACM.

[47]  Donald E. Knuth,et al.  The Art of Computer Programming: Volume 3: Sorting and Searching , 1998 .

[48]  Donald E. Knuth,et al.  The art of computer programming, volume 3: (2nd ed.) sorting and searching , 1998 .

[49]  Stefan Edelkamp,et al.  Policy-Based Benchmarking of Weak Heaps and Their Relatives, , 2010, SEA.

[50]  Edward M. Reingold,et al.  Binary search trees of bounded balance , 1972, SIAM J. Comput..

[51]  Donald E. Knuth The art of computer programming: fundamental algorithms , 1969 .

[52]  Ingo Wegener The Worst Case Complexity of McDiarmid and Reed's Variant of BOTTOM-UP HEAPSORT is less than nlog n + 1.1n , 1992, Inf. Comput..

[53]  Jesper Sindahl Nielsen,et al.  Strictly Implicit Priority Queues: On the Number of Moves and Worst-Case Time , 2015, WADS.

[54]  Marek A. Suchenek,et al.  Elementary Yet Precise Worst-Case Analysis of Floyd's Heap-Construction Program , 2012, Fundam. Informaticae.

[55]  Rudolf Fleischer,et al.  A Lower Bound for the Worst Case of Bottom-Up-Heapsort , 1993, Inf. Comput..