How does a linked list store a sequence using pointers, and how does it differ from an array?
Describe a linked list as nodes joined by pointers, implement insertion and deletion, and contrast it with an array
A focused answer to the H2 Computing outcome on linked lists. Nodes and pointers, traversal, inserting and deleting nodes by relinking, and the trade-offs against arrays for access and modification.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
SEAB wants you to describe a linked list as nodes joined by pointers, implement insertion and deletion, and contrast it with an array. The central idea is that a linked list trades the array's instant indexing for cheap insertion and deletion: because nodes are connected by pointers rather than stored contiguously, you change links instead of shifting elements.
The answer
Nodes and pointers
A linked list is a sequence of nodes. Each node holds a value and a pointer (reference) to the next node. A head pointer marks the start, and the last node's pointer is null to mark the end:
class Node:
def __init__(self, value):
self.value = value
self.next = None
# head -> [A|*] -> [B|*] -> [C|null]
Nodes need not sit together in memory; the pointers thread them into order.
Traversal
To visit every node, start at the head and follow next until you reach null:
def traverse(head):
current = head
while current is not None:
print(current.value)
current = current.next
There is no index arithmetic, so reaching position takes steps: access is .
Insertion and deletion by relinking
The payoff is cheap structural change once you have the right node. To insert node X after node A:
- Set
X.next = A.next(point X at whatever A pointed to). - Set
A.next = X.
The order matters: link X first, or the rest of the list is lost. To delete the node after A, set A.next = A.next.next, bypassing it. No elements shift, so given the position these are .
Linked list versus array
| Operation | Array | Linked list |
|---|---|---|
| Access position | ||
| Insert/delete at front | ||
| Memory layout | contiguous | scattered + pointers |
| Extra memory | none | a pointer per node |
Arrays give instant random access; linked lists give cheap insertion and deletion and grow without reallocation, at the cost of pointer storage and slow indexing.
Examples in context
Example 1. A music playlist. A playlist where songs are frequently inserted and removed mid-list is a natural linked list: dropping a track between two others just reroutes two pointers, with no need to shift the rest of the queue as an array would require.
Example 2. Building stacks and queues. A stack or queue with no fixed capacity is often built on a linked list, because pushing or enqueuing is an relink at one end and the structure grows one node at a time without reallocating a whole array. The linked list provides exactly the cheap end-operations these structures need.
Try this
Q1. State the time complexity of accessing the 5th node of a linked list and explain why. [2 marks]
- Cue. - you must follow
nextpointers from the head, counting steps, with no index arithmetic.
Q2. Describe the pointer changes to delete the node after node A in a singly linked list. [2 marks]
- Cue. Set
A.next = A.next.next, bypassing the node; it is then unreferenced and reclaimed. No elements shift.
Q3. Give one advantage of a linked list over an array. [1 mark]
- Cue. insertion or deletion at the front (or at a known node) by relinking, and it grows without reallocating.
Exam-style practice questions
Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
Original6 marksA singly linked list holds nodes A -> B -> C, where the head points to A and C points to null. Describe the pointer changes needed to (a) insert a new node X between A and B, and (b) delete node B from the original list.Show worked answer →
Each node stores a value and a pointer to the next node.
(a) To insert X between A and B:
- Create node X.
- Set X.next to point to B (the node A currently points to).
- Set A.next to point to X.
Order matters: set X.next before changing A.next, or the reference to B is lost. The list becomes A -> X -> B -> C.
(b) To delete B from A -> B -> C:
- Set A.next to point to C (the node B points to, B.next).
- B is now unreferenced and can be reclaimed.
The list becomes A -> C. No elements are shifted; only pointers are rerouted.
Markers reward creating and linking X in the safe order for insertion, and rerouting A.next to B.next for deletion, with the point that only pointers change.
Original5 marksCompare a singly linked list with an array for (a) accessing the element at a given position, and (b) inserting an element at the front, giving the time complexity of each and a one-line reason.Show worked answer →
(a) Accessing position : an array is - the address is computed directly by index. A linked list is - you must follow next pointers from the head, counting steps, because nodes are scattered in memory with no index arithmetic.
(b) Inserting at the front: a linked list is - create a node, point it at the old head, and update the head. An array is - every existing element must shift right by one to make room.
So arrays win on random access, linked lists win on front (and general) insertion and deletion once the position is known.
Markers reward the two complexities for each operation with correct reasons: index arithmetic versus pointer following, and pointer relinking versus shifting.
Related dot points
- Describe arrays and records as data structures, explain constant-time array indexing and contrast static with dynamic arrays
A focused answer to the H2 Computing outcome on arrays and records. Contiguous storage and constant-time indexing, one and two dimensional arrays, records as fields of mixed type, and static versus dynamic arrays.
- Describe stacks (LIFO) and queues (FIFO), implement their core operations, and identify suitable applications of each
A focused answer to the H2 Computing outcome on stacks and queues. The LIFO stack and FIFO queue, their push, pop, enqueue and dequeue operations with overflow and underflow, and typical applications of each.
- Describe a binary search tree, perform insertion, search and in-order traversal, and explain how balance affects complexity
A focused answer to the H2 Computing outcome on binary search trees. The ordering property, inserting and searching nodes, in-order traversal giving sorted output, and why an unbalanced tree degrades to O(n).
- Describe a hash table and hash function, explain collision resolution by chaining and open addressing, and analyse the effect of load factor
A focused answer to the H2 Computing outcome on hash tables. Hash functions mapping keys to buckets, average O(1) lookup, collisions resolved by chaining or open addressing, and how the load factor affects performance.
- Define recursion in terms of base and recursive cases, trace recursive calls, and compare recursion with iteration
A focused answer to the H2 Computing outcome on recursion. Base and recursive cases, tracing the call stack, the divide-and-conquer pattern, and the trade-offs between recursion and iteration.