Quick revision
The short answer
The gap tells us that linked list exercises teach something real, pointer manipulation and invariants, but that textbook big-O hides what dominates on modern CPUs: cache misses and a separate node object of about 24 bytes per element. ArrayList and ArrayDeque beat LinkedList for almost every workload, so I would teach and assess the reasoning behind a choice, memory layout, allocation, constant factors and JMH measurement, and set standards that default to ArrayList, ArrayDeque and HashMap, ask for a benchmark or justification for LinkedList in review, and are revisited as the platform changes.
What to remember
In this answer, we saw that linked list exercises teach real skills, reference manipulation and invariants, but that the textbook complexity table hides the costs that dominate on modern hardware: a separate node object per element and cache misses from pointer chasing. ArrayList and ArrayDeque therefore win almost every realistic workload. We should teach and assess the reasoning behind a choice, including memory layout and measurement with JMH, set defaults of ArrayList, ArrayDeque and HashMap with justification required for anything else, document the legitimate uses of linked structures, and revisit the rules when the platform changes, for example with Valhalla's value classes.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The gap tells us that linked list exercises teach something real, pointer manipulation and invariants, but that textbook big-O hides what dominates on modern CPUs: cache misses and a separate node object of about 24 bytes per element. ArrayList and ArrayDeque beat LinkedList for almost every workload, so I would teach and assess the reasoning behind a choice, memory layout, allocation, constant factors and JMH measurement, and set standards that default to ArrayList, ArrayDeque and HashMap, ask for a benchmark or justification for LinkedList in review, and are revisited as the platform changes.
Why this question is asked
Many teams interview with linked list puzzles and then never use java.util.LinkedList, and some engineers draw the wrong conclusion in each direction: either that data structures do not matter, or that the textbook complexity table is all they need. A senior engineer is expected to connect the two: to know what the exercise teaches, what it does not, and how that knowledge should show up in everyday code. In this answer, we will look at what linked list exercises are good for, why LinkedList loses on modern hardware, what we should teach and assess instead, the coding standards I would set, and how to keep those standards honest as Java evolves.
1What Linked List Exercises Actually Teach
A linked list exercise is rarely about the list. Reversing a list, detecting a cycle or merging sorted lists trains us to change references in the right order, to keep an invariant true at every step, such as everything before prev is already reversed, and to handle the edge cases at the ends. Those skills matter whenever we work with any graph of objects: entity relationships, trees, caches with eviction order, or concurrent data structures. So the exercises are not useless.
The problem is when the exercise is also taken as a lesson about which collection to use. The textbook says insertion into a linked list is O(1) and insertion into an array is O(n), and that leads people to pick LinkedList for code that inserts often. On real hardware that conclusion is usually wrong.
2Why LinkedList Loses on Modern CPUs
Two costs are missing from the big-O table. The first is memory overhead. Every element of a LinkedList lives in its own Node object holding three references: the item, next and prev. With compressed references, that is a 12-byte object header plus 12 bytes of fields, 24 bytes per node, before counting the element itself. An ArrayList stores the same reference in 4 bytes of a backing array. For a million elements, that is roughly 24 MB of nodes against 4 MB of array.
The second cost is the cache. A CPU reads memory in cache lines of 64 bytes and prefetches the next lines when it sees a sequential pattern. Walking an array reads neighbouring slots, so most reads come from the cache. Walking a linked list follows references to nodes scattered across the heap, and each step can be a cache miss costing on the order of a hundred nanoseconds, against about one nanosecond for a cache hit. So iteration over a large LinkedList can be several times slower than over an ArrayList.
Even the famous O(1) insertion rarely helps. To insert in the middle of a LinkedList we first have to walk to that position, which is O(n) pointer chasing, while ArrayList shifts the elements with System.arraycopy, a fast block move. For realistic sizes the array usually wins. For queues, ArrayDeque is a circular array with O(1) operations at both ends and none of the per-node allocation. Joshua Bloch, who wrote LinkedList, has said publicly that he does not use it himself.
| Operation | ArrayList | ArrayDeque | LinkedList |
|---|---|---|---|
| Memory per element (refs) | about 4 bytes | about 4 bytes | 24 bytes node + 4 |
| Iterate 1 million elements | fast, sequential | fast, sequential | slow, pointer chasing |
| Get by index | O(1) | not supported | O(n) walk |
| Add or remove at the ends | O(1) at end only | O(1) at both ends | O(1), allocates a node |
| Insert in the middle | O(n) block copy | not supported | O(n) walk, then O(1) |
3What We Should Teach and Assess
The fix is not to drop data structures from training, but to teach the reasoning behind choices. When someone picks a collection, they should be able to say how it is laid out in memory, how many objects it allocates, what the constant factors are, and how they would check. Big-O is the start of that reasoning, not the end.
So in interviews I would keep a pointer exercise, because the skill is real, and add a follow-up that asks the candidate to choose a structure for a concrete workload and explain the trade-off: a queue of incoming orders, a list that is read far more often than written, an LRU cache. In internal training I would include a short JMH exercise, because a benchmark that compares ArrayList and LinkedList on the team's own workload is more convincing than any rule, and it teaches people how easy it is to write a misleading benchmark without JMH's warmup and dead-code protection.
4The Coding Standards I Would Set
The standards should make the good choice the default and the unusual choice visible. The default list collection is ArrayList, the default queue or stack is ArrayDeque, and the default map is HashMap, or LinkedHashMap when order matters. Using LinkedList, or an unusual structure such as a hand-written tree or a third-party collection library, needs a short justification in the pull request, ideally with a benchmark on realistic data. A static analysis rule can flag new LinkedList usages, so reviewers do not have to remember.
Standards also need exceptions written down, so people do not fight them. A linked structure is still right when we hold references to nodes and need O(1) removal from the middle, as LinkedHashMap does internally for an LRU cache; for lock-free concurrent queues such as ConcurrentLinkedQueue; for skip lists such as ConcurrentSkipListMap; and for immutable persistent lists that share structure. The rule is about defaults, not prohibition.
5Keeping the Standards Evidence-Based
Performance rules go stale when the platform changes. Project Valhalla is working on value classes, objects without identity that the JVM can store flattened inside arrays and fields, which could change the memory costs of small objects and of collections that hold them. Compact object headers, which shrink the header from 12 to 8 bytes on 64-bit JVMs, are available in recent JDKs as an option; check your version. Each of these changes the numbers behind our rules, though not the cache argument against pointer chasing.
So I would record the reason and the benchmark next to each standard, and review them when we move to a new LTS release, such as from Java 21 to Java 25. If the evidence changes, the standard changes. That keeps the standards from becoming folklore, which is exactly the problem we started with.
6Follow-up questions
When is a linked structure still the right choice?
When its specific strength is the one we need. An intrusive list where we already hold the node gives O(1) removal from the middle, which is how LinkedHashMap keeps access order for an LRU cache. Lock-free queues like ConcurrentLinkedQueue use linked nodes because each producer can link a node with one compare-and-set. Skip lists give sorted concurrent maps. Persistent immutable lists share their tails between versions. And for very large elements that move often, relinking a node can be cheaper than shifting an array. In each case I would still measure.
Should we stop asking linked list questions in interviews?
No, but I would be clear about what they measure: careful reference manipulation and reasoning about invariants. I would pair them with a follow-up about choosing a structure for a real workload, so the candidate also shows they know why java.util.LinkedList is rarely the answer in production.
How would you convince a team that already uses LinkedList everywhere?
With their own data rather than an argument from authority. I would pick one hot path, write a JMH benchmark with realistic sizes and operations, and show the time and allocation difference, plus a heap histogram from production showing the node overhead. Then I would change the default for new code and replace existing uses only where profiling shows they matter, so the migration costs little.
7Conclusion
In this answer, we saw that linked list exercises teach real skills, reference manipulation and invariants, but that the textbook complexity table hides the costs that dominate on modern hardware: a separate node object per element and cache misses from pointer chasing. ArrayList and ArrayDeque therefore win almost every realistic workload. We should teach and assess the reasoning behind a choice, including memory layout and measurement with JMH, set defaults of ArrayList, ArrayDeque and HashMap with justification required for anything else, document the legitimate uses of linked structures, and revisit the rules when the platform changes, for example with Valhalla's value classes.
Open with
I think the gap shows that we teach the right exercise for the wrong lesson. Linked list problems are good for training reference manipulation and invariants, and that skill matters for any object graph, cache or concurrent structure.
Then, if they want more
But people also take away the textbook table, that linked list insertion is O(1), and that is misleading on modern CPUs. Each LinkedList element is a separate node object, about 24 bytes with compressed references, against 4 bytes in an ArrayList's array, and walking the list chases pointers across the heap, so most steps can miss the cache.
Inserting in the middle still needs an O(n) walk, while ArrayList does a fast block copy. So ArrayList and ArrayDeque win almost everywhere, including queues, and even LinkedList's author has said he does not use it.
In training and interviews I would keep the pointer exercises but add the reasoning: memory layout, allocation, constant factors and how to measure with JMH. As standards, the defaults would be ArrayList, ArrayDeque and HashMap, and LinkedList or any exotic structure needs a justification or a benchmark in the pull request, with a static analysis check to flag it.
I would also document the cases where linked structures are right, like LRU ordering inside LinkedHashMap or lock-free queues. Finally, I would keep the rules tied to evidence and review them at each LTS upgrade, because work like Valhalla's value classes may change the numbers.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. 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 "Linked list exercises remain common in interviews, yet in production Java code...": https://scrivio-interview-library.netlify.app/java/coding-problems/3f73b86905/