Skip to content

Big O Complexity

Reference table for common data structures and algorithms.

Data Structures

Data StructureAccessSearchInsertDeleteSpace
ArrayO(1)O(n)O(n)O(n)O(n)
HashMapO(1)*O(1)*O(1)*O(1)*O(n)
Linked ListO(n)O(n)O(1)O(1)O(n)
StackO(n)O(n)O(1)O(1)O(n)
QueueO(n)O(n)O(1)O(1)O(n)

*Average case, worst case O(n)

Algorithms

AlgorithmBestAverageWorstSpace
Binary SearchO(1)O(log n)O(log n)O(1)
Linear SearchO(1)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)
BFS/DFSO(V+E)O(V+E)O(V+E)O(V)

Legend:

  • n = number of elements
  • V = vertices
  • E = edges

Big O Common Patterns

PatternExampleComplexity
ConstantAccess array elementO(1)
LogarithmicBinary searchO(log n)
LinearSimple loopO(n)
LinearithmicMerge sortO(n log n)
QuadraticNested loopsO(n²)
ExponentialRecursive FibonacciO(2ⁿ)

Time vs Space Tradeoff

  • Time complexity: How fast algorithm runs as input grows
  • Space complexity: How much memory algorithm uses as input grows
  • Often you can trade space for time (e.g., memoization) or time for space

When optimizing, consider both based on constraints given in the problem.

Released under MIT License.