skip to content

questions

4

Given only a node in a singly linked list and no head, how do you remove it and when does that fail?

level: middleimportance: should knowfreq 58%

basics

~20 s

Copy the successor's payload into the node you hold, then splice the successor out. The list shrinks correctly, but the object unlinked is the successor. It fails on the last node, which has no successor to borrow from.

open as a page

In a single pass over a singly linked list, how do you advance prev and curr while deleting nodes?

level: middleimportance: should knowfreq 52%

basics

~20 s

Advance prev only when a node survives. After unlinking curr, leave prev where it is and move curr forward alone. Advancing prev unconditionally parks it on an already-removed node, so back-to-back deletions leave the second node linked in.

open as a page

For a linked list node you already hold, when is O(1) removal true and when is it a lie?

level: seniorimportance: should knowfreq 46%

basics

~20 s

Constant-time removal of a held node is true in a doubly linked list, where the node names both neighbours and two writes unlink it anywhere. In a forward-only list it is a lie: finding the predecessor costs O(n).

open as a page