← All cheatsheets

Algorithms & Data Structures

Big-O of Common Operations

Average-case complexity for the data structures and algorithms you reach for in interviews — hash map O(1) average, balanced tree O(log n), comparison sort's O(n log n) floor — plus the worst cases that actually bite.

Updated August 30, 2026 · 5 min read

Data structures (average case)

Array — index accessO(1)
Array — search (unsorted)O(n)
Dynamic array — appendO(1) amortizedO(n) on the resize
Dynamic array — insert/delete at indexO(n)
Hash map — insert / lookup / deleteO(1)O(n) worst: collisions / resize
Balanced BST — search / insert / deleteO(log n)
Binary heap — insert / delete-minO(log n)
Binary heap — peek min/maxO(1)
Linked list — access by indexO(n)
Linked list — insert/delete at known nodeO(1)
Sorted array — searchO(log n)binary search
Trie — lookupO(L)L = key length

Sorting

Comparison-sort lower boundO(n log n)
QuicksortO(n log n) avgO(n²) worst on bad pivots
MergesortO(n log n)stable, O(n) extra space
HeapsortO(n log n)in-place, not stable
Counting / radix sortO(n)bounded integer keys only

Graph & search algorithms

BFS / DFSO(V + E)
Dijkstra (binary heap)O((V + E) log V)
Binary searchO(log n)
Two-pointer / sliding windowO(n)
Topological sortO(V + E)

In the interview

  • State the average AND the worst case. “Hash map is O(1)” is incomplete; the O(n) resize and adversarial collisions are what a Staff interviewer probes.
  • Space complexity is half the answer. Mergesort’s O(n) auxiliary memory is why heapsort or quicksort wins when memory is tight.
  • The O(n log n) comparison-sort floor is why interviewers pivot you to counting/radix when keys are bounded — recognize the tell.