Skip to content
{}

Big-O cheatsheet

Every complexity in this course on one page. Click a name to open the lesson where you build it. * amortised / average · † given a reference to the node

Data structures

StructureAccessSearchInsertDeleteSpace
ArrayO(1)O(n)O(n)O(n)O(n)
Dynamic array (push/pop end)O(1)O(n)O(1)*O(1)O(n)
Singly linked listO(n)O(n)O(1)†O(1)†O(n)
Stack / QueueO(n)O(n)O(1)O(1)O(n)
Hash table—O(1)*O(1)*O(1)*O(n)
Binary search tree (balanced)O(log n)O(log n)O(log n)O(log n)O(n)
Binary search tree (degenerate)O(n)O(n)O(n)O(n)O(n)
Binary heapO(1) minO(n)O(log n)O(log n)O(n)
Trie (word length L)—O(L)O(L)O(L)O(Σ L)
Union-find—O(α(n))O(α(n))—O(n)

Algorithms

AlgorithmBestAverageWorstSpaceNote
Binary searchO(1)O(log n)O(log n)O(1)sorted input
Bubble sortO(n)O(n²)O(n²)O(1)stable
Selection sortO(n²)O(n²)O(n²)O(1)≤ n swaps
Insertion sortO(n)O(n²)O(n²)O(1)stable, great when nearly sorted
Merge sortO(n log n)O(n log n)O(n log n)O(n)stable
Quick sortO(n log n)O(n log n)O(n²)O(log n)in place, fastest in practice
Heap sortO(n log n)O(n log n)O(n log n)O(1)in place, unstable
BFS / DFSO(V + E)O(V + E)O(V + E)O(V)BFS = unweighted shortest path
Topological sortO(V + E)O(V + E)O(V + E)O(V)DAGs only
Dijkstra (binary heap)O((V+E) log V)O((V+E) log V)O((V+E) log V)O(V)no negative weights

Want the intuition behind the notation? Start with lesson 01 — Big-O. Canonical: https://dsa.thebraincord.com/cheatsheet