Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How is LinkedList implemented, and why is it rarely faster than ArrayList in practice, even for inserts?

LinkedList is a doubly linked list: every element lives in its own node object that also holds links to the previous and next nodes. Inserting is O(1) only once we already stand at the position, and getting there is O(n) because the list must walk node by node. Because nodes are scattered on the heap and cost extra memory, while ArrayList shifts a contiguous array with a very fast copy, ArrayList usually wins even for inserts in the middle, and ArrayDeque beats LinkedList as a queue or stack.

Why this question is asked

Textbooks teach that linked lists are good at inserts and arrays are good at lookups, and many developers choose LinkedList on that basis. Interviewers ask this question because the textbook answer is incomplete on real hardware, and a good engineer knows why. In this answer, we will recap how LinkedList is built, look at how get(i) and insert really work, count the memory each element costs, see why CPU caches favour ArrayList, and finish with what to use instead when we need a queue or a stack.

1How LinkedList Is Built

A LinkedList keeps a reference to its first node, a reference to its last node, and a size counter. Each node is a small object with three fields: item, the element itself; next, the following node; and prev, the previous node. Having links in both directions is what makes it doubly linked, and it lets the list walk forwards or backwards and remove a node without searching for its predecessor.

Adding at either end is genuinely cheap: create a node and fix two or three links. That is why LinkedList also implements Deque, the double-ended queue interface, with methods such as addFirst and pollLast.

Step throughA LinkedList holding "a", "b", "c"
  1. LinkedListfirst -> node a, last -> node c, size 3
  2. Node aprev null, item "a", next -> node b
  3. Node bprev -> node a, item "b", next -> node c
  4. Node cprev -> node b, item "c", next null

4 layers, from the top down. Step through them one at a time.

Every element costs a separate node object on the heap.

2Why get(i) Is O(n)

There is no array, so the list cannot jump to position i. It has to start at one end and follow links. LinkedList does one sensible optimisation: if i is in the first half it walks forwards from first, otherwise it walks backwards from last. That halves the work, but it is still proportional to the size.

Java
LinkedList<String> list = new LinkedList<>(List.of("a", "b", "c", "d", "e", "f"));
list.get(1); // "b": walks 1 link from first
list.get(4); // "e": index is in the second half, walks 1 link back from last
list.get(3); // "d": 2 links back from last
// on a list of 1,000,000 elements, get(500_000) follows 500,000 links

Notice that the cost depends on the distance from the nearer end. The middle of the list is the worst place, and it is exactly where the textbook says linked lists shine.

3Insert Is O(1) Only Once We Are There

The famous O(1) insert is about relinking: given a node, a new node can be placed after it by updating four references. But list.add(i, e) is not given a node, it is given an index. So it first walks to position i, which is O(n), and only then does the cheap relink. The total is O(n), the same complexity as ArrayList's add(i, e), which shifts elements instead.

Java
LinkedList<Integer> linked = new LinkedList<>();
ArrayList<Integer> array = new ArrayList<>();
// both are O(n) per call:
linked.add(linked.size() / 2, 7); // walk n/2 nodes, then relink 4 references
array.add(array.size() / 2, 7); // shift n/2 references with one System.arraycopy
ListIterator<Integer> it = linked.listIterator();
while (it.hasNext()) {
if (it.next() % 10 == 0) it.add(-1); // truly O(1): the iterator already stands at the node
}

The insert really is O(1) when we already hold a ListIterator positioned at the right place, as in the loop above. Code that walks the list once and inserts as it goes is the one case where LinkedList has an algorithmic edge. In most code, though, inserts happen by index or by value, and the walk is unavoidable.

4Memory and Cache Locality

Each node costs about 24 bytes on a 64-bit JVM with compressed pointers: a 12-byte object header and three 4-byte references. ArrayList pays 4 bytes per element for its array slot. So LinkedList uses about six times more memory for the list structure itself, before counting the elements.

The bigger cost is where the memory is. A modern CPU reads memory in cache lines of 64 bytes and prefetches the next lines when it sees a sequential pattern. Walking an ArrayList's array reads references in a row, so the hardware keeps the data ready. Walking a LinkedList jumps to wherever each node was allocated, and every hop can be a cache miss costing on the order of 100 nanoseconds. Shifting half of a 10,000-element ArrayList is one memmove of 20 KB, which takes a few microseconds; walking 5,000 scattered nodes can take longer than that.

LinkedList versus ArrayList
OperationLinkedListArrayList
get(i)O(n), walks from nearer endO(1)
add/remove at the endsO(1)end O(1) amortised, front O(n)
add(i, e) in the middleO(n) walk + O(1) relinkO(n) fast block shift
insert via ListIteratorO(1)O(n)
memory per elementabout 24 bytes per nodeabout 4 bytes per slot
cache behaviourpointer chasingsequential, prefetch friendly
Same big O for most operations; the constant factors decide.

5What to Use Instead

For a list, ArrayList is the default, and benchmarks typically show it ahead of LinkedList for middle inserts up to large sizes, because the block copy is so fast. For a queue or a stack, the better choice is ArrayDeque. It is a circular array that supports O(1) adds and removes at both ends, without node objects.

Java
Deque<String> stack = new ArrayDeque<>();
stack.push("a"); stack.push("b");
System.out.println(stack.pop()); // b
Queue<String> queue = new ArrayDeque<>();
queue.offer("x"); queue.offer("y");
System.out.println(queue.poll()); // x
queue.offer(null); // NullPointerException: ArrayDeque rejects nulls

The one behavioural difference to remember is that ArrayDeque rejects null elements, while LinkedList allows them. That is rarely a loss, since null in a queue is ambiguous anyway: poll() returns null to mean the queue is empty.

6Follow-up questions

Is there any case where LinkedList is the right choice?

A few. If the algorithm walks the list once with a ListIterator and inserts or removes many elements during that walk, LinkedList does each change in O(1) where ArrayList would shift. If we need a Deque that allows null elements, LinkedList is the JDK option. These cases are rare, and we should measure before choosing it.

Is LinkedList's size() O(n)?

No. LinkedList keeps a size field that it updates on every add and remove, so size() is O(1). Only index-based access and searches walk the nodes.

Why does ArrayDeque beat LinkedList as a queue when both are O(1)?

Because ArrayDeque stores references in one array and only moves two index counters, while LinkedList allocates a node for every add and leaves it as garbage on every remove. ArrayDeque creates far less garbage and keeps its data together in memory, so the same O(1) has a much smaller constant.

7Conclusion

In this answer, we saw that LinkedList is a doubly linked chain of node objects. get(i) walks from the nearer end in O(n), and insert is O(1) only when an iterator is already at the position, so add(i, e) is O(n) overall, just like ArrayList. Each node costs about six times the memory of an array slot and scatters data across the heap, which defeats CPU caches, so ArrayList usually wins even for middle inserts and ArrayDeque is the better queue or stack.

What to say in the interviewAbout 90 seconds aloud

Open with

LinkedList is a doubly linked list. It holds references to the first and last nodes and a size, and every element lives in its own node object with the item and links to the previous and next nodes.

Then, if they want more

Adding or removing at either end is O(1), which is why it also implements Deque. But get of i has to walk the links, starting from whichever end is nearer, so it is O(n).

The famous O(1) insert is only the relinking once you are already at the node; add at an index first walks there, so it is O(n) overall, the same complexity as ArrayList, which shifts elements with one System.arraycopy. In practice ArrayList usually wins anyway, for two reasons.

Memory: each node is about 24 bytes with compressed pointers, versus 4 bytes per array slot. And locality: the array is contiguous, so the CPU prefetches it, while the nodes are scattered and every hop can be a cache miss. A block copy of thousands of references takes microseconds, often less than walking to the insert position.

The real O(1) case is inserting through a ListIterator during a single pass. For queues and stacks I use ArrayDeque, a circular array with O(1) operations at both ends and no node allocation, keeping in mind that it rejects nulls.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How is LinkedList implemented, and why is it rarely faster than ArrayList in practice...": https://scrivio-interview-library.netlify.app/java/lists/1abcdb2d3c/