---
title: Array vs Linked List: Differences, Timings, When to Use
url: https://www.masaischool.com/resources/array-vs-linked-list-difference
description: Array vs linked list with a decision table, measured Python timings, what cache locality does and does not prove, and interview traps.
updated: 2026-12-01
publisher: Masai (https://www.masaischool.com)
---

# Array vs linked list: the difference and when to use which

> **Short answer**
>
> An array stores items in one contiguous block, so reading by index is O(1) but inserting or deleting in the middle is O(n). A linked list stores nodes scattered in memory joined by pointers, so inserting next to a known node is O(1) but reaching the nth item is O(n). Default to arrays.

Most pages on this topic repeat the same table. This one adds three things: a decision table by situation, a timing script you can run (Python 3.9.6, 1 December 2026), and a plain statement of what memory behaviour does and does not prove.

Background on each structure is in [array data structure explained](https://www.masaischool.com/resources/array-data-structure-explained) and [linked list explained](https://www.masaischool.com/resources/linked-list-explained); this page assumes you have seen both.

## Array vs linked list: the difference in one table

The array wins on reading. The linked list wins on one narrow case: inserting or removing at a position you already hold a pointer to. Everything else follows from contiguous memory versus pointers.

|  | Array (dynamic array) | Singly linked list | Doubly linked list |
|---|---|---|---|
| Memory layout | One contiguous block | Separate nodes joined by next | Separate nodes, next and prev |
| Access by index | O(1) | O(n) | O(n) |
| Insert or delete at the front | O(n) | O(1) | O(1) |
| Insert or delete at the end | O(1) amortised | O(n) without a tail pointer, O(1) insert with one | O(1) with a tail pointer |
| Insert after a known node | O(n) (shift) | O(1) | O(1) |
| Delete a known node | O(n) | O(n) (need previous) | O(1) |
| Search for a value | O(n) | O(n) | O(n) |
| Extra memory per item | None, plus spare capacity | One pointer | Two pointers |
| Needs size up front | No for dynamic arrays; yes for fixed | No | No |

Notice the trap in the third and fifth rows: linked list insertion is O(1) only once you are at the node. Finding the node costs O(n). So 'insert in the middle is faster in a linked list' is false unless you already have the pointer, which is why [LRU caches](https://www.masaischool.com/resources/circular-and-doubly-linked-list-explained) pair a linked list with a hash map.

## Measured: what happens in Python

The script builds a one-million-item list and a one-million-node linked list, then times the same jobs on both.import time class Node: __slots__ = ("val", "next") def __init__(self, val, next=None): self.val, self.next = val, next n = 1_000_000 arr = list(range(n)) head = None for x in range(n - 1, -1, -1): # build 0 -> 1 -> ... -> n-1 head = Node(x, head) def timed(label, f): t = time.perf_counter(); r = f(); ms = (time.perf_counter() - t) * 1000 print(f"{label:34s} {ms:9.3f} ms") return r def sum_list(): return sum(arr) def sum_loop_list(): s = 0 for x in arr: s += x return s def sum_linked(): s, cur = 0, head while cur: s += cur.val; cur = cur.next return s def nth_list(): return arr[n // 2] def nth_linked(): cur = head for _ in range(n // 2): cur = cur.next return cur.val def front_list(): arr.insert(0, -1) def front_linked(): global head head = Node(-1, head) assert timed("sum(list) builtin", sum_list) == timed("sum, python loop over list", sum_loop_list) == timed("sum, python loop over linked list", sum_linked) timed("read middle: list index", nth_list) timed("read middle: walk linked list", nth_linked) timed("insert at front: list", front_list) timed("insert at front: linked list", front_linked)sum(list) builtin 4.608 ms sum, python loop over list 23.307 ms sum, python loop over linked list 49.853 ms read middle: list index 0.002 ms read middle: walk linked list 12.574 ms insert at front: list 0.391 ms insert at front: linked list 0.005 ms

What the numbers say, on one machine and one Python build:

- **Reading the middle item:** the list index was effectively instant, while walking half a million nodes took on the order of ten milliseconds. This is the O(1) versus O(n) difference showing up directly.
- **Inserting at the front:** the linked list was about a hundred times faster, because it creates one node while the list moves a million pointers.
- **Summing everything with a Python loop:** the linked list was roughly twice as slow as the list. Both are O(n). The gap is smaller than the C-level story suggests, because in Python each list slot is a pointer to an int object anyway, so both loops chase pointers.
- **Built-in sum:** far faster than either loop, because it runs in C. Never compare data structures using code that mixes in interpreter overhead and then read it as hardware truth.

So the measurement supports the complexity table, and it also shows that the constant factors in Python are large enough to hide a lot. Repeat it with your own sizes before you quote a ratio.

## Cache locality: what is known and what is not

Modern processors read memory in cache lines (commonly 64 bytes) and keep recently used lines in fast caches. An array scan touches neighbouring addresses, so each fetched line serves several items and the hardware can prefetch the next lines. A linked list scan follows pointers to wherever the allocator placed each node, which can be anywhere. This is why, in languages like C, C++ and Rust, arrays and vectors usually beat linked lists for traversal, often by a large margin, even when both are O(n).

What this does not mean: that the gap is always large, or that it appears in Python. Nodes allocated one after another may land close together, which reduces the penalty. And as the measurement above shows, Python's own overhead dominates. State it carefully in interviews: arrays have better locality, so they are usually faster to traverse in practice. Do not state a specific multiplier unless you measured it in the language and on the data you are discussing.

Memory overhead is easier to check. On this machine a slotted Python node object was about 48 bytes before counting the value it points to:import sys from array import array class Node: __slots__ = ("val", "next") def __init__(self, val, next=None): self.val, self.next = val, next n = 1000 lst = list(range(n)) head = None for x in reversed(range(n)): head = Node(x, head) print("list object + pointers:", sys.getsizeof(lst), "bytes (int objects extra)") print("one slotted Node:", sys.getsizeof(head), "bytes (value object extra)") print("1000 nodes:", sys.getsizeof(head) * n, "bytes vs list pointer array", sys.getsizeof(lst))list object + pointers: 8056 bytes (int objects extra) one slotted Node: 48 bytes (value object extra) 1000 nodes: 48000 bytes vs list pointer array 8056

A list of 1,000 items needs about 8 KB of pointers, while 1,000 node objects need about 48 KB, six times as much, before storing any value. In C the node overhead is smaller (a pointer or two per item), but allocation per node and the pointer cost are still real.

## When to use a linked list: a decision table

| Situation | Use | Reason |
|---|---|---|
| Read by position, loop in order, sort, binary search | Array | Index access and locality |
| Stack | Array (list) | Push and pop at the end are O(1); see [stack](https://www.masaischool.com/resources/stack-data-structure-explained) |
| Queue | collections.deque, a block-linked structure | Front removal O(1); a plain list is O(n); see [queue](https://www.masaischool.com/resources/queue-data-structure-explained) |
| Add and remove at both ends | deque or doubly linked list | O(1) at both ends |
| LRU cache, move a node to the front | Doubly linked list plus hash map | O(1) unlink and relink given the node |
| Splice one list into another without copying | Linked list | Pointer change only |
| Memory-constrained, unpredictable size, no resize pause allowed | Linked list | No large copy on growth |
| Most interview and application code | Array | It is the default for a reason |

Linked lists matter less in everyday Python code than in an exam, but they are the foundation for trees, graphs and hash-table chaining. See [tree data structure explained](https://www.masaischool.com/resources/tree-data-structure-explained) and [hashmap explained](https://www.masaischool.com/resources/hashmap-explained).

## Interview traps

- Saying linked list insertion is O(1) without saying you need the node first.
- Forgetting that deleting a node from a singly linked list needs its previous node.
- Claiming a linked list has no size limit and no waste; it pays a pointer per item.
- Ignoring the empty list and single-node cases. A dummy head node removes most of them.
- Mixing up O(1) amortised and O(1) worst case for dynamic array append.

This code covers the three classic linked list tasks: delete by value with a dummy node, reverse in place, and detect a cycle with two pointers.class Node: def __init__(self, val): self.val, self.next = val, None def build(vals): head = None for v in reversed(vals): n = Node(v); n.next = head; head = n return head def delete_value(head, target): dummy = Node(None); dummy.next = head prev = dummy while prev.next: if prev.next.val == target: prev.next = prev.next.next break prev = prev.next return dummy.next def to_list(h): out = [] while h: out.append(h.val); h = h.next return out def reverse(head): prev = None while head: head.next, prev, head = prev, head, head.next return prev def has_cycle(head): slow = fast = head while fast and fast.next: slow, fast = slow.next, fast.next.next if slow is fast: return True return False h = build([1, 2, 3, 4]) print(to_list(delete_value(h, 1))) # deleting the head: the dummy node handles it print(to_list(reverse(build([1, 2, 3, 4])))) c = build([1, 2, 3]); c.next.next.next = c # tail points back to head print(has_cycle(c), has_cycle(build([1, 2, 3])))[2, 3, 4] [4, 3, 2, 1] True False

Deleting the head works because the dummy node means the head is never a special case. The cycle check moves one pointer one step and the other two steps; if there is a loop they meet. For how to write answers about cost, read [time complexity and Big O](https://www.masaischool.com/resources/time-complexity-and-big-o-explained). More questions are in [DSA interview questions](https://www.masaischool.com/resources/dsa-interview-questions) and the [data structures and algorithms learning path](https://www.masaischool.com/resources/data-structures-and-algorithms).

## Frequently asked questions

### What is the main difference between an array and a linked list?

An array keeps items in one contiguous block and reaches any item by index in O(1). A linked list keeps nodes anywhere in memory, each pointing to the next, so reaching the nth item takes O(n). The array favours reads, the linked list favours insertion next to a node you already hold.

### Which is faster, an array or a linked list?

For reading and scanning, an array is faster, and usually faster in practice too because of cache locality. For inserting or deleting at the front, a linked list is O(1) against O(n). Which one wins depends on the operation and the language.

### When should I use a linked list instead of an array?

Use it when you insert or remove next to a node you already hold, as in an LRU cache or a splice, and you rarely read by position. For most programs an array or dynamic array is the better default.

### Why is insertion in a linked list O(1) but finding the place O(n)?

Inserting changes two pointers, which is constant work. But to reach a position by value or index you must walk from the head, node by node. Total cost is therefore O(n) unless you already have the node.

### Do linked lists use more memory than arrays?

Yes, per item. Each node stores a pointer (two in a doubly linked list) plus allocator overhead, while an array stores only the items, plus some spare capacity. In Python the gap is large because every node is a full object.

### Is a Python list an array or a linked list?

A Python list is a dynamic array of pointers. Indexing is O(1) and inserting at the front is O(n). Python has no built-in linked list; collections.deque is a different structure built from linked blocks.
