04 / 16

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

Constant-Time Head Operations

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).

Difficulty: 2/10

Follow-up Questions

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