Understanding Big O Notation with everyday examples
Master Big O notation with practical examples from daily life.
Ever wondered why some apps get slower when handling more data? Or why Google searches feel instant even with billions of web pages? Let's break down Big O notation using examples we deal with every day!
What’s Big O?
If I have to define the Big O in simplest way possible, I would say these two things -
It’s an upper bound - basically the "worst case scenario" for your code
It means less than or equal to - your code won't perform worse than this limit
Why is it so important?
Imagine - You want to watch a movie and you go to Netflix to search for it. But it takes 10 minutes to give you the search result, instead of the instant results. How is it searching through thousands of movies so fast?
Understanding Big O Notation will help you understand how much time your algorithm will take to run. If you need to give results in half the time, or instantly.
Now, some technical reasons why you need to understand it-
Scale is inevitable - Your app that works fine with 100 users needs to work just as smoothly with 10,000.
Performance = Money - faster code means fewer servers and lower costs.
User Experience - Nobody likes a slow app.
and many more…
TL;DR - Big O in a nutshell:
O(1) - No matter how many inputs you have, you will get the result in the same time (like a vending machine)
O(n) - Linear time: Check all the items once. Time increases directly with input (like finding a song by checking each one)
O(n²) - Quadratic time: Check all possible combinations. Time increases exponentially (like matching socks from a pile)
O(log n) - Logarithmic time: Divider and conquer your problem. Time increases slowly even with large inputs (like finding a word in a dictionary)
Constant Time - O(1) : The vending machine
Imagine a vending machine. Whether there’s 5 or 500 snacks, pressing any button takes the same time to get your snacks. That’s O(1).
# Python
def get_item_from_array(array, index):
return array[index] # Always takes the same time, no matter the array sizeLinear Time - O(n) : Finding a song in your playlist
If you’re looking for a song in your playlist (let’s assume search is not available), you will look at each song one by one till you find the one you’re looking for. That is O(n).
# Python
for songs in songs:
if song == "my song":
return True
return FalseQuadratic Time - O(n²) : Organising your socks
After doing laundry, you take a sock and check all other ones for the matching pair. 10 socks means 100 comparisons. 20 socks? 400 comparisons (20 * 20).
# Python
for first_sock in socks:
for second_sock in socks:
# If colors match, we found a pair
if first_sock == second_sock:
return "found pair"Logarithmic Time - O(log n) : Remember using dictionaries?
When you were finding a word in a dictionary, you don’t just start from first page. You open the middle and check if your word comes before or after, and keep halving your search. The dictionary could have 10,000 words, but you will find yours in about 17 steps (log₂ 10,000 ≈ 13.3). This is why binary search is so fast.
# Python
def binary_search(dictionary, word):
left, right = 0, len(dictionary) - 1
while left <= right:
mid = (left + right) // 2
if dictionary[mid] == word:
return mid
elif dictionary[mid] < word:
left = mid + 1
else:
right = mid - 1Found any mistakes? Have suggestions for additional examples or topics you'd like me to cover? Drop a comment below!
I'm constantly looking to improve and make these explanations more helpful. Whether you're a beginner or an experienced developer, your insights help make this content better for everyone.


Would you like to grab a coffee sometime? Would love to learn more about this topic.