What is the time complexity of inserting and deleting a node in a singly linked list?

Quick Overview

Asks for the time complexity of inserting and deleting nodes in a singly linked list at the head, the tail and positions in between. Tests whether you separate the cost of finding a position from the cost of relinking pointers, and whether you know what a tail pointer does and does not change.

What is the time complexity of inserting and deleting a node in a singly linked list?

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Other

What is the time complexity of inserting and deleting a node in a singly linked list? The answer depends on where in the list the operation happens, so cover the head, the tail and a position in the middle. ```hint Split the work in two Separate the cost of reaching the right place in the list from the cost of changing pointers once you are there. For each case, ask which node's `next` pointer has to change and how you get to that node. ``` ### What a Strong Answer Covers - The cost at the head, at the tail and at an arbitrary position - The split between locating the position and relinking the pointers - What a tail pointer changes for insertion, and why it does not make deletion at the tail fast - The difference between being handed a node reference and being handed a value or an index ### Follow-up Questions - How do these costs change for a doubly linked list? - You hold a pointer only to a node in the middle of a singly linked list. How can you remove it in O(1), and when does that trick fail? - Why does an LRU cache pair a hash map with a doubly linked list? - How does a dummy head node simplify insertion and deletion code?

Overview: Asks for the time complexity of inserting and deleting nodes in a singly linked list at the head, the tail and positions in between. Tests whether you separate the cost of finding a position from the cost of relinking pointers, and whether you know what a tail pointer does and does not change.

General logo
General
Nov 24, 2026
easySoftware EngineerOtherSoftware Engineering Fundamentals
0
0

What is the time complexity of inserting and deleting a node in a singly linked list?

The answer depends on where in the list the operation happens, so cover the head, the tail and a position in the middle.

What a Strong Answer Covers Guidance

  • The cost at the head, at the tail and at an arbitrary position
  • The split between locating the position and relinking the pointers
  • What a tail pointer changes for insertion, and why it does not make deletion at the tail fast
  • The difference between being handed a node reference and being handed a value or an index

Follow-up Questions Guidance

  • How do these costs change for a doubly linked list?
  • You hold a pointer only to a node in the middle of a singly linked list. How can you remove it in O(1), and when does that trick fail?
  • Why does an LRU cache pair a hash map with a doubly linked list?
  • How does a dummy head node simplify insertion and deletion code?