Singly Linked Lists
A singly linked list is a sequence of nodes where each node stores a value and a pointer to the next node.
struct Node {
int value;
struct Node* next;
};The list usually stores a pointer to the head node. It may also store a tail pointer to make appending .
Nodes
A node is not stored next to the next node in memory. Traversal follows pointers from one node to the next:
head -> [value | next] -> [value | next] -> [value | NULL]Because nodes are not contiguous, linked lists have worse cache locality than arrays.
Complexity
| Operation | Without tail pointer | With tail pointer |
|---|---|---|
| Access by index | ||
| Search by value | ||
| Insert at head | ||
| Insert at tail | ||
| Delete head | ||
| Delete tail | ||
| Delete known next node | ||
| Concatenate lists | ||
| Space |
When to Use
Use a singly linked list when you need cheap insertion or removal at the head, stable node references, or simple queue-like behavior with a tail pointer.
Do not use it when you need fast random access, binary search, or tight cache performance. Arrays and dynamic arrays are usually better defaults.