The array is one of the most basic data structures in computer science. (In Python, the built-in array-like data structure is called a list, but I’ll refer to them as arrays, keeping in line with the more general computer science term.) I assume you’ve worked with arrays before, so you’re aware that an array is a list of data elements. The array is versatile and can serve as a useful tool in many situations, but let’s take a look at one quick example.
If you’re looking at the source code for an application that allows users to create and use shopping lists for the grocery store, you might find code like this:
| | array = ["apples", "bananas", "cucumbers", "dates", "elderberries"] |
This array happens to contain five strings, each representing something that I might buy at the supermarket. (You’ve got to try elderberries.)
Arrays come with their own technical jargon.
The size of an array is how many data elements the array holds. Our grocery list array has a size of 5 since it contains five values.
The index of an array is the number that identifies where a piece of data lives inside the array.
In most programming languages, we begin counting the index at 0. So for our example array, "apples" is at index 0, and "elderberries" is at index 4, like this:

To understand the performance of any data structure—such as the array—we need to analyze the common ways our code might interact with that data structure.
Many data structures are used in four basic ways, which we refer to as operations. These operations are:
In this chapter, we’ll analyze how fast each of these operations is when applied to an array.