13 / 16

Why is accessing an element in a Linked List O(n)?

Linked List Access Complexity

javascript
  1. 1

    Accessing the head is O(1).

  2. 2

    Accessing an arbitrary position is O(n) in the worst case.

  3. 3

    The average access cost is also linear for uniformly distributed positions.

  4. 4

    Unlike arrays, linked lists do not support constant-time index calculation.

Difficulty: 2/10

Follow-up Questions

  • Why can arrays access elements in O(1)?
  • Can a linked list provide faster search?