Abstract
The behaviour of three methods for constructing a binary heap is studied. The methods considered are the original one proposed by Williams [1964], in which elements are repeatedly inserted into a single heap; the improvement by Floyd [1964], in which small heaps are repeatedly merged to bigger heaps; and a recent method proposed, e. g., by Fadel et al. [1999] in which a heap is built layerwise. Both the worstcase number of instructions and that of cache misses are analysed. It is well-known that Floyd's method has the best instruction count. Let N denote the size of the heap to be constructed, B the number of elements that fit into a cache line, and let c and d be some positive constants. Our analysis shows that, under reasonable assumptions, repeated insertion and layerwise construction both incur at most cN/B cache misses, whereas repeated merging, as programmed by Floyd, can incur more than (dN log2B)/B cache misses. However, for a memory-tuned version of repeated merging the number of cache misses incurred is close to the optimal bound N/B.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Carlsson, S.: A note on HEAPSORT. The Computer Journal35 (1992), 410–411
Fadel, R., Jakobsen, K.V., Katajainen, J., Teuhola, J., Heaps and heapsort on secondary storage, Theoretical Computer Science220 (1999), 345–362
Floyd, R.W.: Algorithm 245: TREESORT 3. Communications of the ACM7 (1964), 701
Hagerup, T.: Sorting and searching on the word RAM, Proceedings of the 15th Annual Symposium on Theoretical Aspects of Computer Science, Lecture Notes in Computer Science 1373, Springer-Verlag, Berlin/Heidelberg (1998), 366–398
Hayward, R., McDiarmid, C.: Average case analysis of heap building by repeated insertion. Journal of Algorithms12 (1991), 126–153
Hennessy, J.L., Patterson, D.A.: Computer Architecture:A Ouantitative Approach, 2nd Edition. Morgan Kaufmann Publishers, Inc., San Francisco (1996)
Hoare, C.A. R.: Algorithm 65: FIND. Communications of the ACM4 (1961), 321–322
Katajainen, J., Träff, J. L.: A meticulous analysis of mergesort programs. Proceedings of the 3rd Italian Conference on Algorithms and Complexity, Lecture Notes in Computer Science 1203, Springer-Verlag, Berlin/Heidelberg (1997), 217–228
Knuth, D.E.: The Art of Computer Programming, Volume 3: Sorting and Searching, 2nd Edition. Addison Wesley Longman, Reading (1998)
LaMarca, A., Ladner, R. E.: The influence of caches on the performance of heaps. The ACM Journal of Experimental Algorithmics1 (1996), Article 4
LaMarca, A., Ladner, R. E.: The influence of caches on the performance of sorting. Journal of Algorithms31 (1999), 66–104
McDiarmid, C. J.H., Reed, B.A.: Building heaps fast. Journal of Algorithms10 (1989), 352–365
Moret, B.M.E., Shapiro, H.D.: Algorithms from P to NP, Volume 1: Design & Efficiency. The Benjamin/Cummings Publishing Company, Inc., Redwood City (1991)
Saavedra, R.H., Smith, A. J.: Measuring cache and TLB performance and their effect on benchmark runtimes. IEEE Transactions on Computers44 (1995), 1223–1235
Sanders, P.: Fast priority queues for cached memory. Proceedings of the 1st Workshop on Algorithm Engineering and Experimentation, Lecture Notes in Computer Science 1619, Springer-Verlag, Berlin/Heidelberg (1999)
Sedgewick, R.: Implementing Quicksort programs. Communications of the ACM21 (1978), 847–857. Corrigendum, ibidem 22 (1979), 368
Sleator, D. D., Tarjan, R. E.: Amortized efficiency of list update and paging rules. Communications of the ACM28 (1985), 202–208
Spork, M.: Design and analysis of cache-conscious programs, M. Sc. Thesis, Department of Computing, University of Copenhagen, Copenhagen (1999). Available from http://www.diku.dk/research-groups/performance engineering/publications/spork99.ps.gz
Stroustrup, B.: The C++ Programming Language, 3rd Edition. Addison-Wesley, Reading (1997)
Williams, J.W. J.: Algorithm 232: HEAPSORT. Communications of the ACM7 (1964), 347–348
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 1999 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Bojesen, J., Katajainen, J., Spork, M. (1999). Performance Engineering Case Study: Heap Construction. In: Vitter, J.S., Zaroliagis, C.D. (eds) Algorithm Engineering. WAE 1999. Lecture Notes in Computer Science, vol 1668. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-48318-7_24
Download citation
DOI: https://doi.org/10.1007/3-540-48318-7_24
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-66427-7
Online ISBN: 978-3-540-48318-2
eBook Packages: Springer Book Archive