Reading preferences
Concept

Linked Lists and Resizing Arrays

Compare one-way and two-way links with an array that grows when it fills.

linked list, doubly linked list, resizing array, amortised

One-way and two-way chains

In the singly linked list, each node points to the next node. A doubly linked list also keeps a link to the previous node:

None <- [A] <-> [B] <-> [C] -> None

You can follow these links forward or backward. Each extra link uses space and must stay consistent: if A points next to B, B should point previous to A.

Why use them and where they help

With a reference to a node, a doubly linked list can reconnect its neighbours when removing it without first finding its predecessor. A browser history model can use two-way links for previous and next entries, although real implementations may use other structures. Finding an unknown node can still take O(n). Removing the head or tail must also update the stored end.

For A <-> B <-> C, removing B changes A's next link to C and C's previous link to A. If B were the first or last item, update the head or tail instead. An empty list has no head or tail.

A different choice: resizing arrays

An array-like list keeps items in indexed slots. A resizing array has a logical length and an allocated capacity. When full, it can allocate a larger array, copy the existing items, and then append. Consider a teaching example that doubles capacity:

Before appendActionAfter append
length 2, capacity 2Allocate 4 slots and copy 2 itemslength 3, capacity 4
length 3, capacity 4Use an existing slotlength 4, capacity 4

This is an illustration, not a claim about Python's exact growth factor. Python lists are dynamic array-like sequences, not linked lists.

See the reasoning

Follow the example one step at a time

Remove B while keeping both directions of a doubly linked list consistent. This is a prepared teaching demonstration, not live code execution.

Start

head → [A] ⇄ [B] ⇄ [C] ← tail

Each neighbouring pair has a next link and a previous link.

Python illustration

items = []
items.append("A")
items.append("B")
print("first:", items[0])
items.append("C")
print("items:", items)

Prepared output — not live execution:

first: A
items: ['A', 'B', 'C']

The public Python list interface does not expose a portable capacity or guarantee that this particular append triggers a resize.

Time, space, and common mistakes

Indexed array access is O(1); finding a linked-list item by position is O(n). Changing links around a known doubly linked node is O(1), excluding the cost of finding it. With geometric growth, n appends take O(n) total copying and insertion work, so append is O(1) amortised; an individual resize may still cost O(n). Both store O(n) items, but linked nodes need extra links and resizing arrays may keep spare capacity. Other growth policies have different costs. Do not confuse amortised time with a worst-case guarantee for each call.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. What extra link does a doubly linked node usually keep?
2. What must be considered when removing a known doubly linked node?
3. What can happen when a resizing array fills its capacity?
4. Does amortised O(1) append mean every append has constant cost?

References and further reading