Array and linked list: what each one does well
Last updated: 2026-11-26
An array stores its elements side by side, so any slot can be found by computing its position, and a linked list stores each element in a node that carries the location of the next node, so the structure can grow by rewiring links instead of moving elements. Wikipedia defines the array as a collection identified by index, and the linked list as a sequence of nodes with two fields, data and a link. Neither wins on its own; each cost depends on where in the structure your task acts.
Start learning No account needed
1. Two layouts, two cost shapes
Layout explains the costs. In the array, element i sits at a position computed from i, which is why reading any slot costs the same, one step, no matter how much is stored. The price shows up on insertion. Wikipedia's array article notes that a static array's size is fixed when it is created, so adding an element needs either spare room or a new, larger array, and with spare room an insertion in the middle means shifting everything after that point, then writing.
In the linked list, each node holds its data and the link to the next node. Nothing sits at a computable position, so reaching the i-th node means following i links, counting the one from the head pointer; Wikipedia's article says a linked list can only be read in sequence. What the layout buys is cheap structural change: the article states that a list allows insertion and removal at any point in a fixed number of operations, provided the link before the change point is already in hand during the walk. Two link writes, no element moves.
2. A worked example: the same two changes, counted on both
Store the same eight values both ways, leaving the array room for one more, and run two changes: insert 9 at the front, and insert after the last stored value. The script counts moves and writes, step by step:
array, 8 values in 9 slots, insert 9 at the front:
move slots 7..0 right one place: 8 moves, then write the new value: 1 write
total 9 steps
array, insert at the end: 0 moves, 1 write, total 1 step
linked list, insert at the head:
new.link = head (1 write), head = new (1 write): total 2 steps, 0 moves
linked list, insert after the last of 8 nodes, head pointer only:
walk 8 links to reach it, then 2 writes: total 10 steps
linked list with a tail pointer, insert at the end: 2 writes, no walk
read the 7th value: array 1 step (position computed), linked list 7 hops
the cost follows where the change happens: front favors the linked list,
the end and indexed reads favor the array
checks passed
Start with the front insert. The array pays 9 steps, 8 shifts plus 1 write, while the list pays 2 writes and moves nothing. At the end the verdict reverses: the array writes once, while a list with only a head pointer walks all 8 links before its own 2 writes, 10 steps in all. Reading the 7th value shows the array's advantage, 1 computed step against 7 hops. The insert counts depend on where the change happens, so neither structure wins every row.
3. A common misconception: memorize the rankings, then apply them everywhere
It is easy to recite "arrays give constant-time access, linked lists give constant-time insertion" and still be stuck on a real task, because each line carries conditions and the task decides which one matters. The fix is to stop ranking the structures and start reading the workload. Ask three questions of a new task: does it read by position, does it change at the ends or in the middle, and does the walk reach the change point anyway? Our counts map those answers directly: positional reads favor the array, front changes favor the list, end changes favor the array in these counts, although a list that keeps a tail pointer narrows the gap to 2 writes against 1.
The second slip is treating "constant time" as a property of the operation rather than of the situation. Wikipedia's list article attaches its constant-time claim to a condition, the previous link being in hand during a walk, and the same article says that finding a node with a given value may mean walking through nearly the entire list. A constant-time insertion at the head says nothing about a constant-time insertion at the tail of a head-only list, where our script counts 10 steps. Name the operation together with where it acts.
4. Test yourself
Close this page and take one concrete task, such as an undo history that keeps adding newest-first, or a lookup by slot number that changes rarely. Say which structure you would pick, then justify the pick with a count from section 2, including where the change happens. If your justification names no count, it is the recitation again; go back and redo the numbers for your task's shape.
For the surrounding course, see how to study for a computer science exam and how to prepare for a coding interview. For a structure built on top of an array, see what is a hash table. For checking an answer without help, see how to test yourself.
What the sources found, and their limits
Wikipedia, "Array (data structure)". It defines the array as a collection of same-size elements identified by an index, notes that a static array is fixed at creation and cannot insert or remove, describes the dynamic version as reallocating and copying, and states the trade our counts echo: "Linked lists allow constant time removal and insertion in the middle but take linear time for indexed access." Source: Array (data structure), read on 2026-11-25.
Wikipedia, "Linked list". It defines the node with data and a link to the next node, states that insertion and removal at any point take a fixed number of operations when the previous link is kept during traversal, and warns that simple linked lists do not offer random access, with finding a given value among the operations that cost a walk. Its trade-offs section compares linked lists against dynamic arrays directly. Source: Linked list, read on 2026-11-25.
Wikipedia, "Dynamic array". It explains geometric expansion, resizing in big steps, for instance by doubling capacity, so that appending at the end costs amortized constant time, which our FAQ answer uses. Source: Dynamic array, read on 2026-11-25.
Limits: three encyclopedia articles, not a data-structures text. The step counts are ours, computed by scripts/array-vs-linked-list-worked-example.py, which moves array slots and follows list links one at a time; no asymptotic notation is computed or claimed beyond what the articles state. The end-insert comparison assumes a list with only a head pointer, and the script also counts a list that keeps a tail pointer, which pays 2 writes there; the comparison table in the linked list article separates a known end element from an unknown one. All three articles are CC BY-SA.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.
Bring the task you cannot choose for, such as a queue or a lookup table from an assignment. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of handing over the answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.
FAQ
When is a linked list the better choice for a task? When the task keeps changing the structure at places the walk reaches anyway, and rarely reads by position. Our counts show the shape: inserting at the head costs a linked list 2 link writes against the array's 9 steps for 8 stored values, because no element moves. Wikipedia's linked list article states the general rule, that insertion or removal at any point takes a fixed number of operations when the previous link is in hand, while the same article warns the list can only be read in sequence. A queue that adds at one end and removes from the other fits a list that keeps a pointer to each end; a lookup table that reads by position fits the array.
What does a dynamic array change about the trade-off? It removes the fixed-capacity problem without changing the shifting problem. A static array is fixed when it is created, and Wikipedia's array article explains that a dynamic version allocates a new, larger array and copies across when space runs out; the dynamic array article describes reserving space by growing geometrically, such as doubling, so appending at the end costs amortized constant time. What it does not change is our front-insert count: inserting in the middle or at the front still shifts elements, so with spare room our front insert stays at 9 steps.
Start with what you're working on
Tell the tutor which task you are choosing for and let it ask you the questions.
Start learning No account needed
See also: what is binary search · what is a pointer in programming · what is a hash table · stack and queue · how to prepare for a coding interview · how to study for a computer science exam · how to test yourself · all study guides