Big-O notation is like telling how fast a toy car moves based on how many blocks it has to go through.
Imagine you're playing with two toy cars: one is red and the other is blue. Both start at the same point, but they have different paths to reach the finish line.
The red car goes through 10 blocks no matter what, it's like a simple path. We say its speed depends on a constant number of steps, which we write as O(1).
The blue car, however, has to go through more blocks each time, like 2 blocks for the first trip, 4 for the second, and so on. It's like climbing stairs: the higher you go, the more steps you take. We say its speed depends on how many blocks it goes through, which we write as O(n).
Now, picture a race between these cars. If both start at the same time, the red car will always win because it doesn’t have to go farther, it’s like having fewer toys to play with.
So Big-O helps us understand how fast or slow things get as they grow bigger, just like knowing which toy car is faster before you even start the race.
Examples
- Sorting a list of names takes longer when the list grows
- Finding a single item in a large pile is slower than in a small one
- A simple recipe works for any size group, but it gets messy with too many people
Ask a question
See also
- Who is Time Complexity?
- Computational Thinking: What Is It? How Is It Used?
- How algorithms shape what you see on social media?
- Explainer: What Is an Algorithm?
- How Does Big O, Time and Space Complexity: Explained Simply Work?