Skip to main content

Performance Engineering Case Study: Heap Construction

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 1668))

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

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Carlsson, S.: A note on HEAPSORT. The Computer Journal35 (1992), 410–411

    Article  MathSciNet  Google Scholar 

  2. Fadel, R., Jakobsen, K.V., Katajainen, J., Teuhola, J., Heaps and heapsort on secondary storage, Theoretical Computer Science220 (1999), 345–362

    Article  MathSciNet  Google Scholar 

  3. Floyd, R.W.: Algorithm 245: TREESORT 3. Communications of the ACM7 (1964), 701

    Article  Google Scholar 

  4. 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

    Google Scholar 

  5. Hayward, R., McDiarmid, C.: Average case analysis of heap building by repeated insertion. Journal of Algorithms12 (1991), 126–153

    Article  MathSciNet  Google Scholar 

  6. Hennessy, J.L., Patterson, D.A.: Computer Architecture:A Ouantitative Approach, 2nd Edition. Morgan Kaufmann Publishers, Inc., San Francisco (1996)

    Google Scholar 

  7. Hoare, C.A. R.: Algorithm 65: FIND. Communications of the ACM4 (1961), 321–322

    Article  Google Scholar 

  8. 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

    Chapter  Google Scholar 

  9. Knuth, D.E.: The Art of Computer Programming, Volume 3: Sorting and Searching, 2nd Edition. Addison Wesley Longman, Reading (1998)

    Google Scholar 

  10. LaMarca, A., Ladner, R. E.: The influence of caches on the performance of heaps. The ACM Journal of Experimental Algorithmics1 (1996), Article 4

    Article  MathSciNet  Google Scholar 

  11. LaMarca, A., Ladner, R. E.: The influence of caches on the performance of sorting. Journal of Algorithms31 (1999), 66–104

    Article  MathSciNet  Google Scholar 

  12. McDiarmid, C. J.H., Reed, B.A.: Building heaps fast. Journal of Algorithms10 (1989), 352–365

    Article  MathSciNet  Google Scholar 

  13. 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)

    Google Scholar 

  14. Saavedra, R.H., Smith, A. J.: Measuring cache and TLB performance and their effect on benchmark runtimes. IEEE Transactions on Computers44 (1995), 1223–1235

    Article  Google Scholar 

  15. 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)

    Google Scholar 

  16. Sedgewick, R.: Implementing Quicksort programs. Communications of the ACM21 (1978), 847–857. Corrigendum, ibidem 22 (1979), 368

    Article  Google Scholar 

  17. Sleator, D. D., Tarjan, R. E.: Amortized efficiency of list update and paging rules. Communications of the ACM28 (1985), 202–208

    Article  MathSciNet  Google Scholar 

  18. 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

  19. Stroustrup, B.: The C++ Programming Language, 3rd Edition. Addison-Wesley, Reading (1997)

    Google Scholar 

  20. Williams, J.W. J.: Algorithm 232: HEAPSORT. Communications of the ACM7 (1964), 347–348

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics