What is Big O Notation? A Simple Guide
The ultimate cheat sheet for understanding how we measure an algorithm's efficiency and scalability.
The "Why" Before the "What"
Imagine you have two different ways to find a name in a phone book. Method A is to read every single name from A to Z until you find the one you're looking for. Method B is to open the book to the middle, see if the name is before or after, and then repeat that process on the smaller section. Which one is faster?
Intuitively, you know Method B is much faster, especially for a very large phone book. Big O Notation is simply a formal way to describe this difference. It's not about measuring the exact time in seconds, but about understanding how an algorithm's runtime or space requirements grow as the input size (`n`) grows.
Common Complexities Explained Visually
Here are the most common Big O notations you'll encounter. Use the "Next Step" buttons to see how each algorithm progresses and how it maps to the code.