Twice the Stuff, How Much More Work?
Big-O answers one question about any piece of code: if there's twice as much stuff, how much more work is it? Most of the time the answer is the same, twice, or four times.
Novice · Software Development · Updated
After this lesson you can
- Explain what Big-O describes: how the work grows as the amount of data grows
- Predict whether a task's work stays the same, doubles or grows about four times when its data doubles
Key takeaways
- Big-O describes how the work a piece of code does grows as its data grows. It doesn't measure seconds.
- Ask one question: if the data doubles, does the work stay the same, double, or grow about four times?
- Code that feels instant with 50 songs can crawl with 50,000 when its work grows quickly, even though nothing in it changed.
You build a small music app. With your own 50 songs, every button feels instant. Then a friend with 50,000 songs tries it, and the "find duplicate songs" button takes long enough to make a coffee. Nothing is broken, and not a line of code changed. The only thing that changed is the amount of stuff. Developers learn to see this coming before it happens: in code reviews, in a class assignment that asks "how efficient is your solution?", and in nearly every technical interview. The tool they use is called Big-O, and it starts with one question.
The one question
Here it is:
If I have twice as much stuff, how much more work is it?
Stuff is whatever the code works through: songs on a playlist, names on a guest list, orders in a store, rows in a database. Work is the small actions the code takes along the way: looking at one song, comparing two names, adding one to a total.
You don't need any math to answer the question. You need to picture the task with some stuff, then with twice as much, and notice what happens to the work.
Three answers you'll see all the time
Take a playlist of 4 songs, then one of 8, and three things a music app does.
- Play song number 3. The app goes straight to the third spot on the list. With 4 songs or 8, or 8 million, that's the same single move. The work stays the same.
- Find a song by its title, reading from the top. If the song is near the end, or not there at all, you read every title. Twice the songs, twice the titles to read: the work doubles.
- Check for duplicates by comparing every song with every other song. With 4 songs that's 6 comparisons. With 8 songs it's 28. Twice the songs, about four times the work. (The lesson Why the Duplicates Button Crawls: O(n²) shows why it comes out at four.)
| Task | 4 songs | 8 songs | Twice the stuff means… |
|---|---|---|---|
| Play song number 3 | 1 move | 1 move | the same work |
| Find a title, reading from the top | up to 4 titles read | up to 8 titles read | twice the work |
| Compare every song with every other song | 6 comparisons | 28 comparisons | about four times the work |

The third task is the one that made your friend wait. At 50 songs, comparing every pair is about 1,200 comparisons, which a computer finishes in a blink. At 50,000 songs it's about 1.25 billion.
Try it. Deal 8 playing cards face down in a row and look for the ace of spades, turning them over one at a time from the left. Count how many you turn over (if it isn't there, you turned all 8). Then do it again with 16 cards. In the worst case, how many more did you turn?
Why not time it in seconds?
Run the same code on a new laptop and on an old phone, and you get two very different times. Run it while a video is playing, and you get a third. Seconds depend on the machine and on what else it's doing.
How the work grows depends only on the code. A recipe is a good comparison: "twice the guests, twice the potatoes to peel" is true in every kitchen, whether the cook is fast or slow. Big-O is that kind of statement about code. It says how the work grows, so it holds on every computer.
The name: Big-O
The step-by-step method a piece of code follows is called an algorithm. "Find a song by reading every title from the top" is an algorithm; so is "jump straight to spot number 3".
How fast an algorithm's work grows as its data grows is its growth rate, and Big-O notation is the short way developers write a growth rate down. It's called Big-O because it's written with a capital letter O, which stands for "order", as in "the order of growth". You'll see it written in the next lessons, one growth rate at a time, with how to read each one aloud. For now, the three answers above already have names you'll meet again:
- the same work: constant
- twice the work: linear
- about four times the work: quadratic
When someone asks "what's the Big-O of that?", they're asking the one question: if the data doubles, how much more work is it?
Check yourself
2 questions to try on the lesson page.
So what
Every time you write a loop that goes through a list, ask the one question. It's the habit that separates code that works on your laptop from code that keeps working when thousands of people use it.