Handbooks / Data Structures & Algorithms / Chapter 4
Linked Lists, Stacks and Queues
7 pages · ~5 min✓ Reviewed
Builds on String Algorithms. Next up: Sorting and Searching.
Linear Structures: The Mental Model
1. Singly vs doubly linked
- Singly: node = value + next; only
headis known - Index access walks from head: O(n)
- Doubly: node adds prev, one extra pointer per node
| Singly | Doubly | |
|---|---|---|
| Delete given node | O(n) | O(1) |
| Remove tail | O(n) | O(1) |
2. Stack, queue, deque
| Type | Order | Operations |
|---|---|---|
| Stack | LIFO | push / pop / peek, one end |
| Queue | FIFO | enqueue back, dequeue front |
| Deque | both ends | O(1) at both ends |
3. Array vs list
- Array: O(1) index, cache-friendly scans
- List: O(1) insert/delete once you hold the node