Side by side
ArrayvsLinked List
What is the difference between an array and a linked list?
Updated 2 min read7 differences
In short
An array keeps elements side by side in memory, so any item is read instantly by index; a linked list chains nodes with pointers: cheap inserts, slow lookups.
Array
An array is an ordered collection of values stored under one name, where each item is accessed by its numeric position, called an index, usually starting at 0.
Read the page on ArrayLinked List
A linked list is a data structure that stores items in separate nodes, where each node holds a value and a reference to the next node in the chain.
Read the page on Linked ListArray and Linked List compared
| Aspect | Array | Linked List |
|---|---|---|
| Memory layout | One contiguous block of memory | Separate nodes anywhere in memory, linked by pointers |
| Access by index | O(1): jump straight to any position | O(n): walk the list from the head |
| Insert or delete at the front | O(n): every later element must shift | O(1): update a pointer or two |
| Insert at the end | Amortized O(1) for dynamic arrays | O(1) if the list keeps a tail pointer |
| Memory overhead | Low: just the elements, plus spare capacity | Higher: every node also stores one or two pointers |
| Cache performance | Excellent: neighbors are loaded together | Poor: each node may live anywhere in memory |
| Best for | Access by index, iteration and most everyday lists | Frequent inserts and removals at known positions |
The difference, explained
An array is a block of contiguous memory holding elements in order, so the location of item i can be calculated directly. A linked list is a chain of nodes, where each node stores a value and a pointer (a reference) to the next node, and in a doubly linked list to the previous one as well.
The difference comes from memory layout. Because array elements sit side by side, reading arr[500] takes constant time, O(1), but inserting at the front means shifting every other element, O(n). A linked list can insert or remove a node in O(1) once you hold a reference to its neighbor, but reaching the 500th item means walking through the 499 before it.
Arrays are the default in most code, and dynamic arrays such as JavaScript arrays, Python lists and Java's ArrayList grow automatically by copying into a bigger block when full. Linked lists usually appear inside other structures, such as queues, LRU caches and hash table buckets, where cheap inserts and removals matter more than access by index.
A common misconception is that linked lists are faster for inserts in general. The O(1) insert only applies once you already have the right node; finding it is O(n), and because array elements share CPU cache lines, arrays are often faster in practice even for workloads with many inserts.
Which one should you use?
Choose Array when…
- You read elements by index often.
- You mostly append items and loop over them.
- Memory efficiency and cache speed matter.
Choose Linked List when…
- You constantly insert or remove items at the front or middle.
- You already hold references to the nodes you change.
- You are building a queue, a deque or an LRU cache.
Access and insertion in each structure
# Array (a Python list): instant access by index
items = [10, 20, 30, 40]
print(items[2]) # 30, O(1)
items.append(50) # amortized O(1) at the end
items.insert(0, 5) # O(n): every item shifts right# Linked list: each node points to the next one
class Node:
def __init__(self, value, next=None):
self.value = value
self.next = next
head = Node(10, Node(20, Node(30)))
head = Node(5, head) # O(1): new head, nothing shifts
node = head
while node.next: # O(n) to reach the end
node = node.nextReaders ask
Why are arrays usually faster than linked lists?
Array elements are stored next to each other, so the CPU can compute any position directly and load several neighbors into its cache at once. Linked list nodes are scattered, so each step may be a slow trip to memory.
When should I use a linked list?
When you frequently insert or remove elements at positions you already hold a reference to, such as in queues, LRU caches or undo histories, and rarely need access by index.
Is a JavaScript array a linked list?
No. JavaScript engines store arrays as dynamic arrays, switching to a dictionary-like layout for very sparse ones, so access by index is fast.