5 Dynamic arrays: Handling dynamically sized datasets

In this chapter

  • what are the limitations of static arrays
  • overcoming problems with static arrays by using dynamic arrays
  • tradeoffs and when to use dynamic arrays
  • what does it mean to build a dynamic array
  • the best strategies to grow and shrink dynamic arrays

In these first few chapters, we have discovered how versatile arrays are and discussed some of their applications. But have you noticed in all the examples we have seen, the maximum number of elements we can store, and thus the size of the array, is determined in advance and can’t be changed later? This can work in many situations but, of course, not always—it would be naïve to think so.

There are many examples of real-world applications ...

Get Grokking Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.