04 / 16

Why is insertion/deletion at the head of a Linked List O(1)?

Difficulty: 2/10

Constant-Time Head Operations

Insertion or deletion at the head of a linked list is O(1) because it requires changing only a constant number of references. There is no need to shift or traverse the remaining elements.

javascript
  1. 1

    Head insertion requires updating the new node's next reference and head.

  2. 2

    Head deletion only requires moving head to the next node.

  3. 3

    The operation does not depend on the number of nodes.

  4. 4

    Therefore, both operations are O(1).

Follow-up Questions

  • What is the complexity of insertion at the tail?
  • How does a doubly linked list change tail deletion?
Share

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