Singly vs doubly linked
Two common kinds:
- **Singly*: each node points only forward.
- **Doubly*: each node points both forward and back, so you can move in reverse.
Singly: A -> B -> C
Doubly: A <-> B <-> C
Doubly lists cost more memory (two arrows) but let you go backward. Singly lists are simpler and use less space.
When to use a linked list
Use a linked list when you insert and delete a lot and rarely need random access.
| Operation | Array | Linked list |
|---|---|---|
| Access by index | fast | slow |
| Insert at front | slow | fast |
| Insert in middle | slow | fast |
Array: great for reading by number
Linked: great for building and tearing down
If you mostly read data, arrays usually win. If you reorder constantly, linked lists shine.