13 / 16

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

Difficulty: 2/10

Linked List Access Complexity

A linked list does not support direct indexed addressing. To access the element at position k, the program must start at the head and follow next references until it reaches that position. In the worst case, this requires traversing the entire list.

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.

Follow-up Questions

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

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.