“Before you can write efficient code, you need a language to talk about efficiency. Big O is that language – and it’s simpler than you think.”
Imagine you’re searching for your friend’s name in a phonebook. You could start from page one and flip through every single entry until you find it. Or you could open to the middle, check if the name comes before or after, and eliminate half the book instantly. Both approaches work – but one is dramatically smarter. Big O notation is how we put a number on that difference.
If you’ve ever wondered why your code slows to a crawl on large datasets, or why a senior engineer dismisses a solution with “that’s O(n²) – we can’t ship this”, you’re about to gain the vocabulary to understand exactly what they mean.
“Big O isn’t about how fast your code runs — it’s about how fast it slows down.”
What Does Big O Actually Measure?
- It’s not the exact number of operations
- It’s not about a specific machine’s speed
- It’s not always about worst case (though that’s the default)
The Six Complexities You Need to Know
Reading Code Through a Big O Lens
O(1) – Constant time
arr = [10, 20, 30, 40]
first = arr[0] # O(1) — index lookup
cache = {"user": "name"}
name = cache["user"] # O(1) — dictionary lookup
O(n) – Linear time
def find_max(arr):
maximum = arr[0]
for num in arr: # n iterations
if num > maximum:
maximum = num
return maximum
O(n²) – Quadratic time
def bubble_sort(arr):
n = len(arr)
for i in range(n): # outer: n times
for j in range(n - 1): # inner: n times
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
Common Trap: Two separate loops (not nested) is still O(n), not O(n²). Nested loops are what cause quadratic growth. Always look for dependency between loops, not just quantity.
O(log n) – Logarithmic time
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target: return mid
elif arr[mid] < target: left = mid + 1
else: right = mid - 1
return -1 # not found
Space Complexity — The Other Half
Simplification Rules
Quick Reference Cheatsheet
- Array access, hash lookup, stack push/pop
- Binary search, balanced BST operations
- Linear scan, finding min/max, sum of array
- Merge sort, heap sort, most good sort algorithms
- Bubble sort, selection sort, naive nested loops
- Recursive Fibonacci, power set generation
Is O(n²) Ever Okay?
Practice Problems
What’s Next

Comments (...)
You must be signed in to join the discussion.