2 Static arrays: Building your first data structure
In this chapter
- Getting familiar with a few basic ideas in data structures.
- Introducing a fundamental data structure, arrays.
- What is the difference between statically-sized and dynamically-sized arrays?
- Introducing the typical operations you can do on arrays.
- An example of how we use arrays to solve a problem.
With this chapter, we begin to talk about how data structures work and how to implement them. This chapter is special in that it will gently introduce you to the process we will follow throughout the book as we talk about the technology we are introducing. But it will also introduce you to some basic concepts that you will need for the rest of the book.
What is an array?
We will begin our journey into the land of data structures with arrays, specifically static arrays. Arrays organize data by holding a collection of elements and making them accessible through an index.
But right now the most important question we want you to be able to answer is: why arrays? Let me try to explain this with an example.
Memory and drawers
First, we need to take a step back and talk about how memory is organized. For the sake of simplicity, I like to think of memory as a modular shelf that can hold drawers.