Skip to main content

Worst-Case-Efficient Dynamic Arrays in Practice

  • Conference paper
  • First Online:
Experimental Algorithms (SEA 2016)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 9685))

Included in the following conference series:

Abstract

The basic operations of a dynamic array are operator[ ], push_back, and pop_back. This study is an examination of variations of dynamic arrays that support these operations at O(1) worst-case cost. In the literature, many solutions have been proposed, but little information is available on their mutual superiority. Most library implementations only guarantee O(1) amortized cost per operation. Four variations with good worst-case performance were benchmarked: (1) resizable array relying on doubling, halving, and incremental copying; (2) level-wise-allocated pile; (3) sliced array with fixed-capacity slices; and (4) block-wise-allocated pile. Let \(|{\small {\mathcal {V}}}|\) denote the size of the values of type \({\small {\mathcal {V}}}\) and \(|{\small {\mathcal {V}}}{\small {\texttt {*}}}|\) the size of the pointers to values of type \({\small {\mathcal {V}}}\), both measured in bytes. For an array of n values and a slice of S values, the space requirements of the considered variations were at most \(12 |{\small {\mathcal {V}}}| n + O(|{\small {\mathcal {V}}}{\small {\texttt {*}}}|)\), \(2 |{\small {\mathcal {V}}}| n + O(|{\small {\mathcal {V}}}{\small {\texttt {*}}}|\lg n)\), \(|{\small {\mathcal {V}}}| (n + S) + O(|{\small {\mathcal {V}}}{}{\small {\texttt {*}}}|n{\slash }S)\), and \(|{\small {\mathcal {V}}}| n + O((|{\small {\mathcal {V}}}| + |{\small {\mathcal {V}}}{\small {\texttt {*}}}| +|{\small {\mathcal {V}}}{\small {\texttt {**}}}|)\sqrt{n})\) bytes, respectively. A sliced array that uses a few per cent of extra space turned out to be a reasonable solution in practice. In general, for worst-case-efficient variations, the operations were measurably slower than those for the C++ standard-library implementation. Moreover, slicing can make the structures fragile, so measures to make them more robust are proposed.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

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 EPUB and 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

Institutional subscriptions

References

  1. Austern, M.: Defining iterators and const iterators. C/C++ User’s J. 19(1), 74–79 (2001)

    Google Scholar 

  2. Bentley, J.: Programming Pearls, 2nd edn. Addison Wesley Longman Inc., Reading (2000)

    MATH  Google Scholar 

  3. Brodnik, A., Carlsson, S., Demaine, E.D., Munro, J.I., Sedgewick, R.D.: Resizable arrays in optimal time and space. In: Dehne, F., Gupta, A., Sack, J.-R., Tamassia, R. (eds.) WADS 1999. LNCS, vol. 1663, pp. 37–48. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  4. The C++ Standards Committee: Standard for Programming Language C++. Working Draft N4296, ISO/IEC (2014)

    Google Scholar 

  5. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 3rd edn. The MIT Press, Cambridge (2009)

    MATH  Google Scholar 

  6. The CPH STL: Department of Computer Science, University of Copenhagen (2000–2016). http://cphstl.dk/

  7. Goodrich, M.T., Kloss II, J.G.: Tiered vectors: efficient dynamic arrays for rank-based sequences. In: Dehne, F., Gupta, A., Sack, J.-R., Tamassia, R. (eds.) WADS 1999. LNCS, vol. 1663, pp. 205–216. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  8. Katajainen, J., Maniotis, A.M.: Conceptual frameworks for constructing iterators for compound data structures–electronic appendix I: component-iterator and rank-iterator classes. CPH STL Report 2012–3, Department of Computer Science, University of Copenhagen, Copenhagen (2012)

    Google Scholar 

  9. Katajainen, J., Mortensen, B.B.: Experiences with the design and implementation of space-efficient deques. In: Brodal, G.S., Frigioni, D., Marchetti-Spaccamela, A. (eds.) WAE 2001. LNCS, vol. 2141, pp. 39–50. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  10. Katajainen, J., Mortensen, B.B.: Experiences with the design and implementation of space-efficient deques. CPH STL Report 2001–7, Department of Computer Science, University of Copenhagen, Copenhagen (2001)

    Google Scholar 

  11. Katajainen, J., Simonsen, B.: Adaptable component frameworks: using vector from the C++ standard library as an example. In: Jansson, P., Schupp, S. (eds.) 2009 ACM SIGPLAN Workshop on Generic Programming, pp. 13–24. ACM, New York (2009)

    Google Scholar 

  12. Katajainen, J., Simonsen, B.: Vector framework: electronic appendix. CPH STL Report 2009–4, Department of Computer Science, University of Copenhagen, Copenhagen (2009)

    Google Scholar 

  13. Kernighan, B.W., Ritchie, D.M.: The C Programming Language, 2nd edn. Prentice Hall PTR, Englewood Cliffs (1988)

    MATH  Google Scholar 

  14. Kristensen, M.D.: Vector implementation for the CPH STL. CPH STL Report 2004–2, Department of Computer Science, University of Copenhagen, Copenhagen (2004)

    Google Scholar 

  15. Mortensen, B.B.: The deque class in the Copenhagen STL: first attempt. CPH STL Report 2001–4, Department of Computer Science, University of Copenhagen, Copenhagen (2001)

    Google Scholar 

  16. Musser, D.R.: Introspective sorting and selection algorithms. Software Pract. Exper. 27(8), 983–993 (1997)

    Article  Google Scholar 

  17. Neidhardt, M., Simonsen, B.: Extending the CPH STL with LEDA APIs. CPH STL Report 2009–8, Department of Computer Science, University of Copenhagen, Copenhagen (2009)

    Google Scholar 

  18. Plauger, P.J., Stepanov, A.A., Lee, M., Musser, D.R.: The C++ Standard Template Library. Prentice Hall PTR, Upper Saddle River (2001)

    Google Scholar 

  19. Raman, R., Raman, V., Rao, S.S.: Succinct dynamic data structures. In: Dehne, F., Sack, J.-R., Tamassia, R. (eds.) WADS 2001. LNCS, vol. 2125, pp. 426–437. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  20. Sitarski, E.: Algorithm alley: HATs: hashed array trees: fast variable-length arrays. Dr. Dobb’s J. 21(11) (1996). http://www.drdobbs.com/database/algorithm-alley/184409965

  21. Stepanov, A.A., Rose, D.E.: From Mathematics to Generic Programming. Pearson Education Inc., Upper Saddle River (2015)

    Google Scholar 

  22. Stroustrup, B.: The C++ Programming Language, 4th edn. Pearson Education Inc., Upper Saddle River (2013)

    MATH  Google Scholar 

  23. Vandervoorde, D., Josuttis, N.M.: C++ Templates: The Complete Guide. Pearson Education Inc., Boston (2003)

    Google Scholar 

  24. Williams, J.W.J.: Algorithm 232: heapsort. Commun. ACM 7(6), 347–348 (1964)

    Google Scholar 

Download references

Acknowledgements

This work builds on the work of many students who implemented the prototypes of the programs discussed in this paper. From the version-control system of the CPH STL, I could extract the following names—I thank them all: Tina A. G. Andersen, Filip Bruman, Marc Framvig-Antonsen, Ulrik Schou Jörgensen, Mads D. Kristensen [14], Daniel P. Larsen, Andreas Milton Maniotis [8], Bjarke Buur Mortensen [9, 10, 15], Michael Neidhardt [17], Jan Presz, Wojciech Sikora-Kobylinski, Bo Simonsen [11, 12, 17], Jens Peter Svensson, Mikkel Thomsen, Claus Ullerlund, Bue Vedel-Larsen, and Christian Wolfgang.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jyrki Katajainen .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this paper

Cite this paper

Katajainen, J. (2016). Worst-Case-Efficient Dynamic Arrays in Practice. In: Goldberg, A., Kulikov, A. (eds) Experimental Algorithms. SEA 2016. Lecture Notes in Computer Science(), vol 9685. Springer, Cham. https://doi.org/10.1007/978-3-319-38851-9_12

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-38851-9_12

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-38850-2

  • Online ISBN: 978-3-319-38851-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics