Arrays vs Linked Lists: When to Use Each
Picture a playlist with a million songs. Adding one song to the top, jumping to song 500,000 and pressing the back button are three everyday actions, and arrays and linked lists are fast at completely different ones.
Data structures · 2026-11-25 · 6 min read
How each one is stored
An array keeps its items side by side in one block of memory. Item 500,000 sits at a position the computer can calculate: start + 500,000 × item size. A linked list stores each item in its own node, anywhere in memory, and each node holds a pointer to the next one.
Jumping to an item: arrays win
Because array positions can be calculated, songs[500000] is one step: O(1). A linked list has no shortcut: to reach song 500,000 you follow 500,000 “next” pointers from the start: O(n).
Adding to the front: linked lists win
To put a song at the top of an array, every existing song shifts one place to make room: a million moves, O(n). In a linked list you create one node, point it at the old first node, and update the head pointer: O(1), however long the list is.
# Linked list: add to the front in O(1)
node = Node("New song")
node.next = head
head = nodeThe back button: doubly linked lists
A singly linked list only knows the way forward, so going back one song means starting again from the head. A doubly linked list gives each node a prev pointer too, so stepping backwards is O(1). Browser history, undo stacks and LRU caches use exactly this.
Big-O side by side
| Operation | Array | Linked list |
|---|---|---|
| Read item i | O(1) | O(n) |
| Add / remove at the front | O(n) | O(1) |
| Add at the end | O(1) on average (dynamic array) | O(1) with a tail pointer |
| Add / remove in the middle | O(n) | O(1) once you are at the node |
| Search for a value | O(n) | O(n) |
| Memory per item | Just the item | Item + 1 or 2 pointers |
Which one real code uses
Most of the time, a dynamic array: Python’s list, Java’s ArrayList, JavaScript arrays, C++’s vector. Items sitting together in memory are very cache-friendly, so arrays are often faster in practice even where the Big-O looks similar.
Linked lists earn their place when you add and remove at both ends or in the middle very often and already hold a pointer to the spot: queues (Python’s collections.deque), LRU caches, schedulers and memory allocators.
Tip: Need fast adds at the front? In Python use collections.deque, in Java ArrayDeque, instead of list.insert(0, x).
See it happen
In the interactive lesson you run a music app with a million-song playlist. Add to the top, jump to the middle, press back: you pick the structure each time and watch the songs shift or the arrows re-link.
Play: arrays vs linked lists →
Frequently asked questions
What is the main difference between an array and a linked list?
An array stores items next to each other, so any position can be read instantly. A linked list stores items in separate nodes joined by pointers, so adding or removing at a known spot is instant but reaching item i means walking there.
Why is inserting at the front of an array O(n)?
Every existing item has to shift one position to make room, so the work grows with the number of items.
When should I use a linked list?
When you frequently add or remove items at the ends or at a position you already hold a reference to, such as queues, deques and LRU caches. For most other cases a dynamic array is faster.
Is a Python list an array or a linked list?
A dynamic array. Reading by index is O(1), appending is O(1) on average, and inserting at the front is O(n). collections.deque is the fast choice for both ends.