Big-O notation explained by counting steps: constant, logarithmic, linear and quadratic growth with real numbers, how to read it from code, and when it does not matter.
Big-O has a reputation for being maths-heavy and interview-only. It is neither. It answers one practical question: when my data gets bigger, how much slower does this get? A page that is fine with 100 records and unusable with 100,000 has a Big-O problem, and you can see it coming without running anything.
How to count steps instead of seconds, what the four common growth shapes look like with real numbers, how to read the shape off a piece of code, and when you can safely ignore all of it.
Seconds depend on your computer. Steps do not. Say n is the number of items. If the work is "look at every item once", that is about n steps, so doubling the data doubles the work. Big-O is just the habit of describing work as a function of n, and keeping only the part that dominates as n grows. A program that takes 3n + 7 steps is simply "O(n)", because for large n the 3 and the 7 stop mattering compared with the shape.
| Name | Big-O | Example | n = 10 | n = 1,000 | n = 1,000,000 |
|---|---|---|---|---|---|
| Constant | O(1) | Read item number 5 of a list | 1 | 1 | 1 |
| Logarithmic | O(log n) | Binary search in a sorted list | about 4 | about 10 | about 20 |
| Linear | O(n) | Check every item once | 10 | 1,000 | 1,000,000 |
| Quadratic | O(n²) | Compare every item with every other | 100 | 1,000,000 | 1,000,000,000,000 |
Read the last column slowly. A million items cost a million steps when linear, but a trillion when quadratic. That is why the difference decides whether something works at all.
The same question can have different costs depending on how the data is stored. "Is this name in my list?" on an unsorted list means checking items one by one: O(n). On a sorted list, binary search does it in O(log n). In a hash table or set, it is O(1) on average. The answer is identical; only the cost changes. This is the real reason to learn data structures, and it is the thread in Data Structures: How to Actually Start.
For small n, the shape does not matter. Sorting 50 items any way you like is instant. Big-O starts to bite when n can grow: records in a database, rows in a file, users on a site. A sensible habit is to write the clear version first, and think about growth when the data can become large. If you are unsure, measure.
In Python, this compares membership checks in a list and in a set of the same 100,000 numbers. Run it and compare the two times:
import time
n = 100_000
as_list = list(range(n))
as_set = set(as_list)
t = time.perf_counter(); [x in as_list for x in range(0, n, 50)]; print("list:", time.perf_counter() - t)
t = time.perf_counter(); [x in as_set for x in range(0, n, 50)]; print("set: ", time.perf_counter() - t)
Then double n and run it again. The list time should grow far faster than the set time. That gap is O(n) against O(1), measured on your own computer.
Put these shapes to work in Data Structures: How to Actually Start. If "an algorithm" still feels abstract, What Computer Science Actually Is shows where it fits in the bigger picture.
A sane starting point for DSA that avoids the two common traps — grinding problems with no understanding, and drowning in theory with no practice — plus the order to learn topics in.
An honest picture of what a computer science degree really is before you start — problem-solving over memorization, why it's not just 'learning to code', and how to set the right expectations for four years.