Skip to content

What is the difference between an array and a linked list

An array stores elements in contiguous memory and provides O(1) random access, while a linked list stores each element in a separate node with a pointer to the next, giving O(n) search but O(1) insertion or deletion at known positions. Arrays have fixed or resize‑costly size; linked lists grow one node at a time.

Computer Science · Data structures


An array is a fixed‑size collection whose elements occupy consecutive memory addresses. Because the address of element i can be computed as base + i × size, reading or writing any position takes constant time, O(1). The downside is that the size must be known ahead of time or the whole block must be reallocated when it grows. If the array runs out of space, a new larger block is allocated and every element is copied, which can be costly. Arrays also waste memory when allocated larger than needed.

Key Characteristics

Main differences between arrays and linked lists:

  • Contiguous vs. scattered storage
  • Fixed size vs. dynamic growth
  • Fast random access vs. fast insertion/deletion
  • Higher memory overhead for pointers

A linked list stores each element in a separate node that contains the data field and a pointer (or two pointers for a doubly linked list) to the next node. Because nodes are allocated individually, the total size can grow or shrink one element at a time without moving existing data. The trade‑off is extra memory for each pointer, typically 8 bytes on a 64‑bit machine, and the need for dynamic allocation, which can fragment the heap. In practice, a list of 1 000 integers may consume roughly 1 000 × (4 bytes + 8 bytes) ≈ 12 KB, compared with 4 KB for a plain array.

Insert a node at the front of a singly linked list:

  1. 1Create a new node containing the value
  2. 2Set the new node’s next pointer to the current head
  3. 3Update the head pointer to the new node

Arrays benefit from spatial locality: consecutive elements are fetched together into the CPU cache, so iterating over an array is usually faster than traversing a linked list whose nodes are scattered throughout memory. Each pointer chase in a list can cause a cache miss, forcing the processor to wait for data from main memory. This difference becomes dramatic in tight loops, such as summing one million numbers, where an array version can run several times quicker than a linked‑list version even though both perform the same arithmetic.

Time‑complexity comparison of common operations:

OperationArrayLinked List
Access by indexO(1)O(n)
Insert at frontO(n) (shift)O(1)
Delete at frontO(n) (shift)O(1)

Choose an array when you need fast random access, predictable memory usage, and good cache performance, especially for fixed‑size or rarely resized collections. Opt for a linked list when the application performs many insertions or deletions at the front or middle and the exact size is unknown in advance. Remember that a linked list does not magically make searching faster; locating a value still requires scanning nodes sequentially. Understanding these trade‑offs lets you select the structure that matches the algorithmic requirements of your program.

Check yourself

Which data structure gives O(1) time for inserting at the front without moving existing elements?

Get this as a lesson built for you

Describe what you are studying and Lernex writes the lesson and the questions around it. Free, and it takes about a minute.

Try it

No account needed to try it.

What people ask next