DSA · Patterns, not puzzles

How do arrays and linked lists differ?

Easyarrayslinked-listsdata-structuresUpdated Oct 2026
Quiz this track

Short answer

Arrays store elements contiguously, giving O(1) index access but costly inserts and deletes. Linked lists store nodes connected by pointers, giving O(1) insertion at a known position but O(n) lookup.

The difference is memory layout. An array reserves a contiguous block, so the address of any element can be computed directly. A linked list scatters nodes and connects them with references, so reaching a position requires walking from the head.

js
class ListNode {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

function prepend(head, value) {
  const node = new ListNode(value);
  node.next = head;
  return node;
}
Prepending to a linked list is O(1). Prepending to an array with shift is O(n).

The practical comparison

  • Array access by index is O(1); linked list access is O(n)
  • Inserting at the front of an array is O(n); prepending a node is O(1)
  • Arrays have better cache locality because elements are contiguous
  • Linked lists need extra memory for pointers
  • Deleting a node from a linked list is O(1) if you already hold the previous node

In JavaScript, arrays are dynamic and usually the right default. Linked lists matter when you are constantly splicing at known positions, implementing a queue with O(1) removal, or building structures where node identity is useful.

Big O hides constants. A linked list can be slower than an array even for operations where its asymptotic complexity is better, because pointer chasing hurts cache performance.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why is array access O(1)?
  2. 2When is a linked list actually the better choice?
  3. 3How do you find the middle of a linked list?
  4. 4Why is cache locality important here?

Say it in the interview

Arrays use contiguous memory, so index access is constant time, but inserting or deleting in the middle shifts elements. Linked lists use nodes and pointers, so insertion at a known node is constant time, but reaching that node is linear. In JavaScript I usually default to arrays because they are fast and cache-friendly. I reach for a linked list when I need cheap splicing or a queue with constant-time removal.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live DSA mock interview and get scored feedback on depth, clarity and confidence.