Skip to main content

Updated Sep 3, 2026

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​

StructureSearch / accessInsertDeleteMemory overhead
Static arrayO(1)O(1) index (worst)O(n)O(n) worst — shiftO(n)O(n) worst — shiftNone beyond the elements
Dynamic arrayO(1)O(1) index (worst)O(1)O(1) amortized at the back; O(n)O(n) worst elsewhereO(n)O(n) worstUnused capacity past current size
Singly linked listO(n)O(n) worstO(1)O(1) worst given the node/positionO(1)O(1) worst given the previous nodeOne next pointer per node
Doubly linked listO(n)O(n) worstO(1)O(1) worst given the nodeO(1)O(1) worst given the nodeTwo pointers per node
Stack (array-backed)O(n)O(n) worst — not built for searchO(1)O(1) amortized pushO(1)O(1) worst popSame as its backing array
Queue (ring-buffer-backed)O(n)O(n) worstO(1)O(1) worst enqueueO(1)O(1) worst dequeueFixed array, no per-slot overhead
Hash tableO(1)O(1) average, O(n)O(n) worstO(1)O(1) amortized averageO(1)O(1) averageLoad-factor slack: unused slots below the resize threshold
BST (unbalanced)O(log⁡n)O(\log n) average, O(n)O(n) worstO(log⁡n)O(\log n) average, O(n)O(n) worstO(log⁡n)O(\log n) average, O(n)O(n) worstTwo child pointers per node
Balanced tree (AVL / red-black)O(log⁡n)O(\log n) worst, guaranteedO(log⁡n)O(\log n) worstO(log⁡n)O(\log n) worstTwo child pointers plus balance metadata (height or colour) per node
Binary heapO(1)O(1) peek extreme (worst); O(n)O(n) worst for an arbitrary valueO(log⁡n)O(\log n) worstO(log⁡n)O(\log n) worst extractContiguous array, no per-node overhead
Graph, adjacency listO(deg⁡(u))O(\deg(u)) worst — "is there an edge u→v?"O(1)O(1) worst — add edgeO(deg⁡(u))O(\deg(u)) worst — remove edgeO(V+E)O(V + E) total
Union-FindO(α(n))O(\alpha(n)) amortized — "same set?"n/a (merge only)Not supportedOne or two int arrays
TrieO(L)O(L) average, LL = key lengthO(L)O(L) averageO(L)O(L) average, with ancestor pruningPer-node overhead × branching factor (array) or × children present (hash map)
Segment treeO(log⁡n)O(\log n) worst — range queryO(log⁡n)O(\log n) worst — point updaten/a — fixed size≈4n\approx 4n node slots as commonly implemented
Fenwick treeO(log⁡n)O(\log n) worst — prefix queryO(log⁡n)O(\log n) worst — point updaten/a — fixed sizeExactly one array of n+1n + 1 ints
Deque, block-basedO(1)O(1) at either end; O(n)O(n) middle (collections.deque) or O(1)O(1) middle (std::deque)O(1)O(1) amortized at either endO(1)O(1) amortized at either endOne block-pointer directory, plus partially-full end blocks
Ring bufferO(1)O(1) indexO(1)O(1) worst pushO(1)O(1) worst popNone beyond the fixed array
Bloom filterO(k)O(k) query — "possibly present" onlyO(k)O(k) insertNot supported (plain form)mm bits, fixed regardless of how full
Count-min sketchO(d)O(d) estimate — overestimate onlyO(d)O(d) addNot supportedd×wd \times w counters, fixed
HyperLogLogO(1)O(1) amortized estimate, ~2% errorO(1)O(1) amortized addNot supportedA few KB, independent of cardinality
Skip listO(log⁡n)O(\log n) expectedO(log⁡n)O(\log n) expectedO(log⁡n)O(\log n) expected~2 pointers/node expected (geometric level distribution)
LRU cacheO(1)O(1) worst — getO(1)O(1) worst — put, including evictionO(1)O(1) worst — evictionHash map + one doubly linked list
LFU cacheO(1)O(1) worst — getO(1)O(1) worst — put, including evictionO(1)O(1) worst — evictionHash 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.
  • 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.