Model answer
Given node x and its predecessor p=x->prev, set new->prev=p and new->next=x, then p->next=new and x->prev=new. With valid sentinels or boundary handling, this changes four links in O(1).
Use the key terms, then explain the reasoning.
Doubly linked nodes keep both next and previous links, allowing bidirectional traversal and constant-time removal of a known node.
A doubly linked node contains previous and next links. The extra direction enables reverse traversal and removal of a known node without searching for its predecessor.
Sentinel head and tail nodes can eliminate most boundary branches: every real node then always has neighbours, and insertion becomes the same four-link operation at every position.
| Operation | Best | Average | Worst | Extra space |
|---|---|---|---|---|
| Search | O(n) | O(n) | O(n) | O(1) |
| Insert at either end | O(1) | O(1) | O(1) | O(1) |
| Delete known node | O(1) | O(1) | O(1) | O(1) |
| Indexed access | O(n) | O(n) | O(n) | O(1) |
A sentinel-free implementation must update both ends and both directions carefully.
Open a prompt when you are ready to check your answer.