More Comparisonbeginner

Array vs Linked List: Key Differences

Arrays give instant access by index; linked lists change links instead of moving items. See the costs, the code in Java and C, and how to choose.

6 min read

Our verdict in 30 seconds

An array keeps items side by side, so reading any index takes O(1) time, but inserting in the middle moves other items. A linked list keeps items in nodes joined by links, so inserting at a known place is O(1), but finding an index takes O(n). Use an array by default and a linked list when cheap changes at known nodes matter.

On This Page

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:

  1. Reverse an array without extra space: reverse an array in place.
  2. Reverse a linked list in Java.
  3. Find the middle node with slow and fast pointers.
  4. Build a stack and a queue with each structure, then compare stack vs queue.
  5. 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?
Arrays are usually faster for reading and looping because items sit together in memory. Linked lists can be faster for adding or removing at a node you already have. The operation decides the winner.
Why is insertion in a linked list sometimes called O(n)?
Changing the links takes O(1). Finding the position may take O(n) because you must walk from the head. If you have only an index, the total is O(n).
Can binary search work on a linked list?
It can be written, but it loses its main benefit because reaching the middle takes linear time. Use an array for normal binary search. Balanced trees or skip lists are better when you need changes and fast search.
Is ArrayList an array or a linked list?
ArrayList is a list that stores its items in an array inside. When the array is full, it creates a bigger one and copies the items. LinkedList is the Java class that uses linked nodes.
Does a linked list use more memory than an array?
Usually yes, for the same number of items, because each node also stores one or two links. An array with a lot of empty spare space can waste memory too. Compare the real case.

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

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 3 December 2026 LinkedIn

More comparisons

View all
Chat with us