
Drumroll please everyone!! Big O (in a nutshell) notation describes how an algorithm’s runtime grows as the input size increases. It provides an asymptotic description of the algorithm’s performance, thus focusing on behaviour for large inputs.
Therefore, if you couldn’t tell already, Big O represents an upper bound on growth and is commonly used to describe the worst-case performance. It applies to both time complexity and space complexity. Additionally, it compares algorithms independently of hardware or programming language and helps us understand how efficiently an algorithm will scale.
Big O is matters a lot since it helps to predict how an algorithm can behave with larger inputs, guides developers into choosing the most efficient algorithm, ensures your code can handle growth without crashing or slowing down and is, of course, a must-know for technical interviews and coding challenges.
Common Complexity Classes
In the lab, we would generally categorise our algorihms into the following primary growth tiers:
| Notation | Name | Description |
|---|---|---|
| O(1) | Constant | Execution time is independent of the input size. |
| O(\log n) | Logarithmic | Time grows slowly as n increases (such as Binary Search). |
| O(n) | Linear | Time grows proportionally with input size. |
| O(n \log n) | Linearithmic | Typical of efficient sorting algorithms (such as a Merge Sort). |
| O(n^2) | Quadratic | performance degreades quickly (such as a Bubble Sort). |
While O(n) may seem all good and wonderful for smaller data sets, when we are dealing with enterprise-grade data streams, the difference between O(n \log n) and O(n^2) is the difference between a millisecond response and a system-wide timeout.
# O(n) example
def linear_search(arr, target):
for item in arr:
if item == target:
return True
return False
# O(n^2) example
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
Big O isn’t just about time – it also describes how much memory your algorithm uses.
- O(1) space – You would use a fixed amount of memory, no matter the input size.
- O(n) space – You store something for each input element. Similar to copying an array.
Understanding Big O isn’t just academic mumbo jumbo. It helps write code that doesn’t just work, but code that words very well, even when the stakes (and said data) gets very big.
So maybe the next time you’re choosing between a brute-force loop, or a clever divide and conquer approach you should always remember: Big O is your best friend!
It’s like an anchor that keeps your programs from wandering into the land of timeouts and crashes.


Leave a Reply
You must be logged in to post a comment.