Ad Space — Top Banner

Big O Notation Reference

Understand Big O notation for algorithm complexity.
Covers O(1), O(log n), O(n), O(n log n), O(n2), and O(2n) with examples.

What is Big O?

O(f(n)) describes the upper bound of an algorithm's growth rate as input size n increases

Big O notation describes the worst-case performance of an algorithm. It tells you how the running time or memory usage grows as the input gets larger.

Common Complexities (Fastest to Slowest)

Big ONameExample
O(1)ConstantArray index lookup, hash table access
O(log n)LogarithmicBinary search
O(n)LinearScanning through a list
O(n log n)LinearithmicMerge sort, quick sort (average)
O(n²)QuadraticBubble sort, nested loops
O(n³)CubicMatrix multiplication (naive)
O(2ⁿ)ExponentialRecursive Fibonacci, power set
O(n!)FactorialTraveling salesman (brute force)

Growth Comparison

nO(log n)O(n)O(n log n)O(n²)O(2ⁿ)
10310331001,024
100710066410,0001.27 × 10³⁰
1,000101,0009,9661,000,000Huge
10,0001310,000132,877100,000,000Huge

Example 1

What is the time complexity of searching for a value in a sorted array using binary search?

Binary search halves the search space each step

After k steps, the remaining space is n / 2ᵏ

It stops when n / 2ᵏ = 1, so k = log₂(n)

Time complexity: O(log n)

Example 2

What is the time complexity of checking all pairs in an array of n elements?

The outer loop runs n times

The inner loop runs up to n times for each outer iteration

Total operations: n × n = n²

Time complexity: O(n²)

When to Use It

Use Big O notation to evaluate and compare algorithms:

  • Choosing the right data structure for a given problem
  • Predicting performance as data grows from hundreds to millions of records
  • Identifying bottlenecks in code during optimization
  • Communicating algorithmic efficiency in technical discussions

Ad Space — Bottom Banner

Embed This Calculator

Copy the code below and paste it into your website or blog.
The calculator will work directly on your page.