← Back to resources

June 4, 2026 • Parth Narkar

Big O Notation Explained Simply

A clear, beginner-friendly guide to understanding Big O notation, including common time complexities from O(1) to O(2ⁿ) with practical code examples.

What is Big O?

  • Measures how algorithm performance scales with input size
  • Not about actual speed (seconds), about growth rate
  • Helps compare algorithms objectively
  • Ignore constants and smaller terms

Common Complexities (Best to Worst)

O(1) - Constant Time

  • Same time regardless of input size
  • Examples: Array access by index, hash map lookup
  • Code: array[5] or dictionary['key']

O(log n) - Logarithmic Time

  • Divides problem in half each step
  • Examples: Binary search in sorted array
  • Growth: Very slow, efficient for large datasets

O(n) - Linear Time

  • Time grows proportionally with input
  • Examples: Single loop through array, simple search
  • Code: for item in array: print(item)

O(n log n) - Linearithmic Time

  • Common in efficient sorting algorithms
  • Examples: Merge sort, quick sort (average case)
  • Growth: Faster than O(n²), slower than O(n)

O(n²) - Quadratic Time

  • Time grows with square of input size
  • Examples: Nested loops, bubble sort
  • Code:
for i in array:
    for j in array:
        # do something