An array keeps elements of the same type in a fixed-size, contiguous block of memory, making indexed access fast and direct. Its capacity is set when it’s created, unlike a linked list that can grow as needed. See how arrays differ from stacks and queues, too.

Multiple Choice

What data structure stores a fixed-size sequence of elements of the same type?

An array is a data structure that stores a fixed-size sequence of elements of the same type. It allocates a contiguous block of memory for a specified number of items, so every slot is reserved in advance. Because all elements share the same type and are laid out contiguously, you can access any position directly with its index in constant time, which makes lookups fast. The fixed-size aspect means the capacity is set when the array is created and doesn’t change automatically, unlike structures that can grow or shrink. A linked list arranges elements in separate nodes connected by pointers, so the total number of elements can vary and memory isn’t necessarily contiguous. A stack stores items with a last-in, first-out access pattern, and a queue uses first-in, first-out order; both describe how elements are used, and they can be implemented using arrays or linked lists, but they aren’t defined by storing a fixed-size sequence of identical elements in a single contiguous block. Therefore, the data structure that matches a fixed-size sequence of elements of the same type is the array.

Arrays: A Simple Way to Store Data in Order

An array stores a sequence of elements in numbered positions. In a traditional array, each element has the same data type, and the array’s size is set when it is created. That simple setup gives arrays one of their most useful features: you can jump straight to a particular position instead of searching through every item before it.

Think of an array as a row of mailboxes. Each box has a number, and each one holds a value of the same kind—perhaps an integer, a character, or a temperature reading. The boxes sit in a fixed order, so finding box 12 is straightforward. This basic idea appears throughout computer science, from small programs to large systems that process images, sensor readings, or financial data.

What makes an array an array?

An array is a collection of elements stored under one name and reached by their positions, or indices. In many programming languages, indexing starts at zero. So an array with five elements has positions 0 through 4, not 1 through 5.

For example, an integer array might look like this:


[14, 27, 31, 42, 58]

The value at index 0 is 14; the value at index 3 is 42. The index acts like an address within the collection.

In a conventional fixed-size array, the program reserves room for a set number of elements when it creates the array. If it creates space for five integers, the array has five slots. Those slots don’t automatically appear or disappear as values are added or removed. This makes an array different from a collection designed to grow freely.

The elements also share a type in many traditional languages. An integer array holds integers; a character array holds characters. That rule lets the system calculate how much room each element needs and where each one belongs.

Why direct access is so fast

In many implementations, an array’s elements occupy a continuous block of memory. “Continuous” here means that the slots sit next to one another, like houses along a single street. If the program knows the starting address, the element size, and the index, it can calculate where any element lives.

A simplified address calculation is:


element address = starting address + (index × element size)

Suppose each integer uses four bytes. To reach the element at index 3, the system moves 12 bytes from the start address: 3 × 4. It doesn’t need to inspect indices 0, 1, and 2 along the way.

That’s why accessing an array element by index usually takes O(1) time, also called constant time. The array could contain ten elements or ten million; a direct lookup still takes a predictable number of steps, assuming the index is valid. For data that gets read often, this is a big advantage.

There’s a useful contrast here: arrays make it easy to reach a known position, but they can be less convenient when the collection needs frequent changes. Speed comes with a little rigidity.

Fixed size: a strength and a limitation

A fixed capacity can make memory use predictable. A program that needs to store exactly 24 hourly readings, for instance, can create an array with 24 slots and know the space is reserved. That can simplify code and keep access quick.

But what if the program later needs 25 readings? A fixed-size array can’t simply stretch itself in place. The usual approach is to create a larger array, copy the existing values into it, and then use the new array. That extra work can take time and memory.

Some languages offer structures that feel like arrays but can expand. Java’s ArrayList, C++’s std::vector, and JavaScript arrays can grow as items are added. These structures often use an array underneath. When their current storage fills up, they allocate a larger block and copy the elements across. So the convenient, expandable collection is built on the same idea—but it adds a layer that manages resizing.

Language details matter, too. In C, an array’s size is typically fixed after it is created in a given context, though programmers can allocate memory dynamically. Java arrays have a fixed length. Python’s list, despite often being described casually as a list or array-like collection, can grow and can hold values of different types. It’s helpful to distinguish a language’s everyday container from the traditional fixed-size array concept.

Arrays beside other data structures

Arrays are only one way to organize data. A linked list, stack, and queue solve related problems, but each is defined by a different feature.

A linked list stores values in nodes. Each node points to the next one, and sometimes also to the previous one. The nodes don’t need to sit next to one another in memory. A linked list can grow or shrink as nodes are added or removed, but reaching the element at a particular position generally means following links from the beginning. If the target is far down the list, that can take O(n) time.

A stack describes how items are added and removed: last in, first out. Imagine a pile of plates. The last plate placed on top is the first one you lift away. A queue uses first in, first out, like people waiting at a café counter. In either structure, the emphasis is on the order of access, not on a particular memory layout. A stack or queue can be built using an array or a linked list.

That distinction is easy to miss. An array describes a way to store a sequence; a stack or queue describes a way to manage access. They aren’t competing labels for the same feature.

Where arrays show up

Arrays are useful whenever data has a natural order and the program needs to retrieve items by position. A digital image, for example, can be represented as a two-dimensional array of pixels. A spreadsheet-like grid is another familiar case: a row and column identify a location. Audio samples, game-board cells, and daily weather readings can all fit into arrays.

Arrays also support many higher-level structures. A matrix is essentially an arrangement of values in rows and columns. A heap, often used to build a priority queue, can be stored in an array. Sorting algorithms may rearrange array elements, while search algorithms use their indices to locate values.

Even when a program uses a more flexible container, arrays may be doing quiet work behind the scenes. They’re the sturdy shelves in the storage room: not always the whole system, but often the part that keeps things organized and easy to reach.

Choosing the right structure

An array is a strong fit when the number of elements is known or manageable, the values share a type, and quick indexed access matters. It’s less convenient when the collection changes size often or when items must be inserted near the beginning. Inserting at index 0, for example, may require shifting every later element one position to make room.

That doesn’t make arrays outdated. It just means the choice depends on the job. A linked list can make some insertions easier, while an array can make repeated lookups much faster. A queue can express a clear first-in, first-out rule, and an array can provide its storage. Computer science often works this way: one structure supplies the memory layout, while another idea governs how data is used.

Arrays remain a core concept because their rules are clear and their performance is easy to reason about. They store an ordered sequence, often of one type, in a set of positions. And when a program knows the index, it can reach the value directly—one small calculation, then there it is.