Why This Matters
Linked lists are the first structure where location is not the same thing as index. Each node says where to go next. That makes insertion at a known node cheap and random access expensive.
Core Idea
A singly linked node stores (value, next). A doubly linked node stores (prev, value, next).
| Operation | Singly linked list cost |
|---|---|
| read first item | |
| read item at index | |
| insert after known node | |
| delete after known node | |
| search by value |
Worked example: to find the 50th node, a linked list must follow 50 pointers. An array computes the address directly.
Common Mistakes
- Saying insertion is always . It is only after you already have the node or iterator.
- Forgetting to update both links in a doubly linked list.
- Ignoring cache misses. Pointer chasing can lose badly to array scans even when asymptotic costs look similar.
Exercises
- Draw the pointer changes for deleting a node from a singly linked list.
- Explain why linked-list binary search is not useful.
- Implement cycle detection with two pointers.
Next Topics
References
- Cormen, Leiserson, Rivest, Stein. Introduction to Algorithms (4th ed., 2022). Ch. 10.
- Skiena. The Algorithm Design Manual (3rd ed., 2020). Ch. 3.