Data Structures Cheat Sheet
This page is a reference, not a tutorial — each page in this section explains the reasoning behind the row it gets here. Every complexity below names its case (best / average / amortized / worst); the full argument for each lives on that structure's own page.
Operation-cost matrix
| Structure | Search / access | Insert | Delete | Memory overhead |
|---|---|---|---|---|
| Static array | index (worst) | worst — shift | worst — shift | None beyond the elements |
| Dynamic array | index (worst) | amortized at the back; worst elsewhere | worst | Unused capacity past current size |
| Singly linked list | worst | worst given the node/position | worst given the previous node | One next pointer per node |
| Doubly linked list | worst | worst given the node | worst given the node | Two pointers per node |
| Stack (array-backed) | worst — not built for search | amortized push | worst pop | Same as its backing array |
| Queue (ring-buffer-backed) | worst | worst enqueue | worst dequeue | Fixed array, no per-slot overhead |
| Hash table | average, worst | amortized average | average | Load-factor slack: unused slots below the resize threshold |
| BST (unbalanced) | average, worst | average, worst | average, worst | Two child pointers per node |
| Balanced tree (AVL / red-black) | worst, guaranteed | worst | worst | Two child pointers plus balance metadata (height or colour) per node |
| Binary heap | peek extreme (worst); worst for an arbitrary value | worst | worst extract | Contiguous array, no per-node overhead |
| Graph, adjacency list | worst — "is there an edge u→v?" | worst — add edge | worst — remove edge | total |
| Union-Find | amortized — "same set?" | n/a (merge only) | Not supported | One or two int arrays |
| Trie | average, = key length | average | average, with ancestor pruning | Per-node overhead × branching factor (array) or × children present (hash map) |
| Segment tree | worst — range query | worst — point update | n/a — fixed size | node slots as commonly implemented |
| Fenwick tree | worst — prefix query | worst — point update | n/a — fixed size | Exactly one array of ints |
| Deque, block-based | at either end; middle (collections.deque) or middle (std::deque) | amortized at either end | amortized at either end | One block-pointer directory, plus partially-full end blocks |
| Ring buffer | index | worst push | worst pop | None beyond the fixed array |
| Bloom filter | query — "possibly present" only | insert | Not supported (plain form) | bits, fixed regardless of how full |
| Count-min sketch | estimate — overestimate only | add | Not supported | counters, fixed |
| HyperLogLog | amortized estimate, ~2% error | amortized add | Not supported | A few KB, independent of cardinality |
| Skip list | expected | expected | expected | ~2 pointers/node expected (geometric level distribution) |
| LRU cache | worst — get | worst — put, including eviction | worst — eviction | Hash map + one doubly linked list |
| LFU cache | worst — get | worst — put, including eviction | worst — eviction | Hash map + frequency map + one doubly linked list per frequency |
"My input looks like this → reach for…"
Two notes on reading this flow: it asks about the query, not the data's storage format, because the same array of numbers is a job for a hash table, a segment tree, or a plain sorted array depending entirely on which operation runs the most; and several branches are not mutually exclusive in a real system — a production LRU cache in front of a database is itself often backed by a hash table for lookup, so "reach for the LRU cache" is a decision about policy, not a replacement for the hash table underneath it.
Recall
References
- Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms, 4th ed. — Ch. 10 (elementary structures), Ch. 11 (hash tables), Ch. 12–14 (search trees), Ch. 19 (union-find), Ch. 21 (graph representations): the chapters this page's rows summarise.
- Sedgewick & Wayne, Algorithms, 4th ed., §3.5 "Applications" and §1.3 "Bags, Queues, and Stacks" — the symbol-table framing this cheat sheet's "what does the query need" framing follows.
Related Pages
- Data Structures — Overview — the section's starting point, for the reasoning behind why this folder is organised the way it is.
- Hash Tables — the single most common answer on the decision flow above, and the baseline every other row is compared against.
- Complexity Cheat Sheet — the growth-rate table and "how large an n is affordable" reference this page's Big-O notation assumes.
- Trees & Binary Search Trees — the shared vocabulary (node, root, height) that segment trees, tries, and balanced trees all specialise differently.