skip to content

Linked Lists

Node-and-pointer lists: how they live in memory, the singly/doubly/circular variants, and the core pointer manipulations interviewers expect you to explain step by step. Linked lists are the classic probe for whether you truly understand references, ownership of the 'next' pointer, and cost models beyond Big-O labels.

part ofData structures & algorithmsoverview, primer and where to startread it →
on this pageshow

explore

questions

page 2 of 2

Why does traversal of a long-lived linked list slow down as its nodes get scattered?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Complexity does not change — both passes are O(n) — but the constant does. A chain built in one burst tends to sit in nearby memory; after months of churn its surviving nodes are spread out, and each hop becomes a memory access that cannot begin until the previous one returns.

open as a page

Why is a three-branch delete (empty, head, scan) a dummy-head refactor and not just style?

level: seniorimportance: should knowfreq 40%

basics

~10 s

All three branches exist because the first node has no predecessor. A dummy head supplies one, collapsing them into a single scan-and-relink and deleting the head-reference reassignment where the real defects live.

open as a page

Two-speed detection or a visited set for a traversal job hung on a looping escalation chain?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Decide on what the incident needs. The two-speed walk costs no extra memory and still yields the loop's entry, but re-walks records; remembering every record seen costs memory proportional to the chain and hands you the entire offending path in one pass.

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

Why is merge sort the natural sort for a linked list but quicksort is not?

level: seniorimportance: should knowfreq 57%

basics

~20 s

Merge sort only reads forward and joins two sorted chains by rewriting links, so its usual output buffer disappears on a list. Quicksort and heapsort assume random access — index arithmetic and cheap in-place swaps — which a chain cannot supply.

open as a page

What does a one-pass gap-pointer walk to the kth-from-last node buy over counting the length first?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Not asymptotic speed — both are O(n) and both perform roughly 2n advances. One pass buys a single sweep from the head, which matters when re-walking is expensive or the cursor cannot be restarted. Counting first is usually the clearer code.

open as a page

Recursive list reversal is called O(1) space; why does that fail on a 10-million-node feed?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Recursion is not free space: the call stack holds one frame per node, so depth equals list length. Ten million pending frames exhausts the stack long before the walk finishes, making the recursive version O(n) auxiliary space, not O(1).

open as a page

A diff swaps a trade blotter's backing array for a linked list to make middle inserts O(1). What is your review?

level: seniorimportance: should knowfreq 52%

basics

~20 s

Reject it as written. The O(1) splice applies only at a node already held; a blotter inserting at a found position still walks O(n), and that walk over scattered nodes measures far worse than the array's contiguous shift of the same length.

open as a page

In an order book where cancels hold a node handle, what does a linked list guarantee that a compacted array does not?

level: seniorimportance: should knowfreq 40%

basics

~20 s

A linked list gives every resting order a stable identity: unrelated inserts and removals never move a node, so a handle taken at insert time is still valid at cancel time. An array index names a position, and compaction or growth silently renames every later order.

open as a page

Is the prev pointer worth its memory across 10 million nodes, and what do you lose without it?

level: principalimportance: should knowfreq 38%

basics

~20 s

Keep prev only for backward movement or O(1) unlink at externally held nodes. At ten million nodes it costs a machine word each — tens of megabytes. If deletes happen during a traversal you already run, a trailing reference does the same for free.

open as a page

Which bugs does a dummy head sentinel fail to prevent, and which one does it add?

level: middleimportance: nice to knowfreq 28%

basics

~20 s

A sentinel only removes the missing-predecessor branches. Length, search, iteration and the value handed back to callers must all start after it, and a sentinel carrying a default payload can be matched by a scan that forgets to skip it.

open as a page

When does a skip list beat a balanced search tree for a concurrently updated, price-ordered catalog index?

level: seniorimportance: nice to knowfreq 34%

basics

~20 s

A skip list wins when many threads mutate the index: its updates rewire a few neighbouring pointers with no rebalancing, so fine-grained locking and lock-free variants stay tractable, and its bottom level scans price ranges in order. A balanced tree wins when worst-case bounds or memory are contractual.

open as a page

Your team's standard bans linked lists outright. When would you overrule it, and how would you justify that?

level: principalimportance: nice to knowfreq 30%

basics

~20 s

Overrule the ban only when a property, not a speed hunch, demands it: worst-case constant-time operations with no runtime allocation, or element identity that must survive unrelated mutation. Justify with a measurement, scope it to one module behind an interface, and document the exception.

open as a page

showing 31–43 of 43