In array vs linked list, the key point is how items are placed in memory. An array keeps them side by side. A linked list keeps each item in a node, and every node points to the next one. Arrays win for access by position. Linked lists win for adding or removing at a place you already hold.
Array vs linked list: the verdict table
| Point | Array | Linked list |
|---|---|---|
| Memory layout | One continuous block | Separate nodes joined by links |
| Read by index | O(1) | O(n) |
| Size | Fixed for a basic array | Grows node by node |
| Insert at start | O(n) | O(1) |
| Insert after a known item | O(n), later items shift | O(1) |
| Extra memory | Little per item | Link space per node |
| CPU cache use | Good | Often poor |
| Binary search on sorted data | Good | Not useful |
Default choice: use an array or a growing array. Pick a linked list for a clear reason.
Array vs linked list in data structure: a simple picture
Think of an array as seats in one row of a cinema. Seat 7 is easy to find because seats are numbered in order. To place a new person in the middle without a gap, everyone after that point must move one seat.
Think of a linked list as a treasure hunt. Each clue tells you where the next clue is. Adding a clue in the middle is easy if you are standing there: change two notes. But to reach clue 7, you must follow the first six.
Array: [10][20][30][40]
Linked list: 10 -> 20 -> 30 -> 40 -> null
The address of an array item can be found with a formula:
address = start + index * item size
That is why reading is O(1). A linked list has no such formula, because its nodes may be anywhere in memory.
Three kinds of linked list
- Singly linked: each node knows the next node. It uses the least memory.
- Doubly linked: each node knows the next and the previous node. You can walk both ways.
- Circular: the last node points back to the first. This suits turns that repeat.
When a question does not say which kind, ask. The cost of deleting the last node depends on it.
Array vs linked list time complexity
| Operation | Array | Singly linked list |
|---|---|---|
| Get item at index i | O(1) | O(n) |
| Search unsorted data | O(n) | O(n) |
| Search sorted data | O(log n) | O(n) |
| Insert at start | O(n) | O(1) |
| Insert at end | O(1) if space is free | O(1) with tail, otherwise O(n) |
| Insert at index i | O(n) | O(n) to find, O(1) to link |
| Delete first | O(n) | O(1) |
| Delete last | O(1) | O(n), even with a tail |
Two rows need care. In a singly linked list, deleting the last node needs the node before it, and there is no link back. A doubly linked list with a tail makes that O(1).
A growing array, such as Java's ArrayList, adds at the end in amortised O(1). Most adds are cheap. A few are costly because the items are copied into a bigger array.
Common mistake: Saying "linked list insertion is O(1)" and stopping. Add the condition: O(1) if you already have the node. Finding it may take O(n).
Array vs linked list in Java
This program inserts 15 between 10 and 20 in both structures.
public class InsertDemo {
static class Node {
int value;
Node next;
Node(int value) {
this.value = value;
}
}
public static void main(String[] args) {
int[] a = {10, 20, 30, 0};
int size = 3;
for (int i = size; i > 1; i--) {
a[i] = a[i - 1];
}
a[1] = 15;
System.out.println(java.util.Arrays.toString(a));
Node head = new Node(10);
head.next = new Node(20);
head.next.next = new Node(30);
Node fresh = new Node(15);
fresh.next = head.next;
head.next = fresh;
StringBuilder out = new StringBuilder();
for (Node n = head; n != null; n = n.next) {
out.append(n.value).append(" -> ");
}
System.out.println(out + "null");
}
}
Output:
[10, 15, 20, 30]
10 -> 15 -> 20 -> 30 -> null
The array moved two items. The list moved none and changed only links. Notice the order: first point the new node at the old next node, then change head.next. If you reverse those lines, you lose the rest of the list.
In real Java code you use ArrayList or LinkedList instead of writing nodes. That choice has its own details, covered in ArrayList vs LinkedList. For queue work, ArrayDeque is usually the first choice.
Array vs linked list in C
In C you can see the memory idea directly.
#include <stdio.h>
struct Node {
int value;
struct Node *next;
};
int main(void) {
int a[3] = {10, 20, 30};
struct Node third = {30, NULL};
struct Node second = {20, &third};
struct Node first = {10, &second};
printf("%d\n", a[2]);
printf("%d\n", first.next->next->value);
return 0;
}
Both lines read the value 30. The array reaches it in one step with an index. The list follows two pointers. Here the nodes are local variables, so there is nothing to free. Real C lists usually create nodes with malloc, and then each node needs one free. Save the next pointer before you free a node.
Memory and the CPU cache
Big O does not show everything. A computer loads nearby memory together into a fast area called the cache. Array items sit side by side, so loading one often loads its neighbours. A walk through an array is friendly to this.
Linked nodes can be far apart. Each step may need a slower memory read. This is why an array can beat a linked list in some real programs, even when the list looks equal in Big O.
Memory use is different too. A node for one small number stores the number and at least one link. In Java, each node is also an object with its own overhead. An array has little extra cost per item, but a growing array may keep spare space.
Pro tip: If you are unsure, write the code with a growing array first and measure. Change it only if the test shows that shifting items is the problem.
Choose an array if / choose a linked list if
Choose an array if
- you read by index often
- you loop through all items many times
- you need binary search
- memory should be compact
Choose a linked list if
- you add and remove at the start often
- you already hold the node to change
- you are joining or splitting chains of nodes
- items must not move when another item is added
Real examples: image pixels and marks fit an array. The linked entries inside a hash map bucket use links. An LRU cache often joins a hash map with a doubly linked list: the map finds the node, and the list moves it in O(1).
A worked choice
Suppose you store the last 50 songs a user played and always add at the front. A plain array would shift up to 49 items each time. A linked list changes a few links. A third answer is better than both for many cases: a circular array, where the start position moves instead of the items. This is the idea inside ArrayDeque. Good design is sometimes a smarter array, not a list.
Freshers: the array vs linked list difference in interviews
Give the answer in four steps: memory, access, insertion, choice.
30-second answer: "An array stores items in one block, so index access is O(1). A linked list stores nodes with links, so access is O(n). Inserting in an array may shift items. Inserting at a known list node is O(1). I use an array by default and a linked list when I need frequent changes at known nodes."
Then practise these:
- Reverse an array without extra space: reverse an array in place.
- Reverse a linked list in Java.
- Find the middle node with slow and fast pointers.
- Build a stack and a queue with each structure, then compare stack vs queue.
- Check for a loop in a linked list.
Draw boxes and arrows before writing list code. It prevents many lost links. The DSA guide gives the wider order of topics.
Interview note: Common follow-ups are "Can you delete a node without the head?", "Why is the list slower to loop through?" and "How would you make delete-last O(1)?" The last answer is a doubly linked list with a tail.
Frequently Asked Questions
Which is faster, an array or a linked list?
Why is insertion in a linked list sometimes called O(n)?
Can binary search work on a linked list?
Is ArrayList an array or a linked list?
Does a linked list use more memory than an array?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — Discover CodeBegun's Java Full Stack track

