Big O Time Complexity Cheat Sheet

Every complexity class with real operation counts, and the exact time and space complexity of every algorithm on VizStep — each linked to a step-by-step visualization where you can watch the growth rate happen.

The Complexity Classes

ClassNamen = 10n = 100n = 1,000,000Examples
O(1)Constant111Hash table lookup, stack push/pop
O(log n)Logarithmic~3~7~20Binary search, balanced-tree operations
O(n)Linear101001,000,000Linear search, array traversal
O(n log n)Linearithmic~33~664~2×10⁷Merge sort, quicksort (average), heapsort
O(n²)Quadratic10010,00010¹²Bubble/selection/insertion sort, nested loops

Operation counts are approximate and illustrate growth — the point is the shape, not the exact numbers. At a million elements, the gap between O(n log n) and O(n²) is the gap between ~20 million operations and a trillion.

Every Algorithm on VizStep

AlgorithmBestAverageWorstSpace
Stack (LIFO)O(1)O(1)O(1)O(n)
Queue (FIFO)O(1)O(1)O(1)O(n)
Linked ListO(1)O(n)O(n)O(n)
Binary Search TreeO(log n)O(log n)O(n)O(n)
AVL TreeO(log n)O(log n)O(log n)O(n)
Min/Max HeapO(1)O(log n)O(log n)O(n)
Hash TableO(1)O(1)O(n)O(n)
BFS (Breadth-First)O(V+E)O(V+E)O(V+E)O(V)
DFS (Depth-First)O(V+E)O(V+E)O(V+E)O(V)
Dijkstra's AlgorithmO(V+E)O(V²)O(V²)O(V)
Linear SearchO(1)O(n)O(n)O(1)
Binary SearchO(1)O(log n)O(log n)O(1)
Bubble SortO(n)O(n²)O(n²)O(1)
Selection SortO(n²)O(n²)O(n²)O(1)
Insertion SortO(n)O(n²)O(n²)O(1)
Merge SortO(n log n)O(n log n)O(n log n)O(n)
Quick SortO(n log n)O(n log n)O(n²)O(log n)

Frequently Asked Questions

What does Big O notation actually measure?

Big O describes how an algorithm’s running time (or memory) grows as the input size grows — its growth rate, not its actual speed. Constants and lower-order terms are dropped: an algorithm doing 3n² + 5n + 20 operations is simply O(n²), because for large inputs the n² term dominates everything else.

Is an O(log n) algorithm always faster than an O(n) one?

Not for small inputs. Big O describes growth as n gets large; at n = 10 the constant factors can easily make the "slower" algorithm win. That is why production sorting libraries switch to insertion sort — asymptotically worse — for small subarrays. Asymptotics win eventually, not immediately.

What is the difference between best, average, and worst case?

They describe the same algorithm on different inputs. Quicksort averages O(n log n) on random data but degrades to O(n²) on adversarial input with naive pivots; insertion sort is O(n) on already-sorted data but O(n²) on reversed data. Worst case matters for guarantees, average case for typical performance.

What is the fastest possible comparison-based sort?

O(n log n) is a proven lower bound for comparison-based sorting — no algorithm that only compares elements can beat it in the general case. Sorts that appear faster, like counting sort or radix sort, sidestep the bound by exploiting structure in the keys instead of comparing elements.