Understanding Time Complexity & Big-O Notation
Learn how to measure algorithm efficiency and make smart design choices
The Library vs. The Messy Pile
Real-World Scenario
Imagine you need to find a specific book. You have two options:
Option A: The Organized Library
Books are sorted alphabetically on shelves. You know exactly which aisle and shelf to check.
- • Walk to correct section
- • Check specific shelf
- • Find book in seconds
- • Time: Almost instant
Option B: The Messy Pile
Books are scattered randomly in a huge pile on the floor. No organization whatsoever.
- • Pick up first book, check title
- • Not it? Try next one
- • Keep checking one by one
- • Time: Could take hours
The Key Insight
The number of steps you take depends on how the data is organized. With 10,000 books, the library approach might take 14 checks maximum, while the pile approach could take all 10,000 checks in the worst case. This difference is what Big-O notation measures.
Keep reading — this lesson marks itself done automatically.