Big-O notation describes an upper bound on how an algorithm’s cost grows with input size. In beginner algorithm practice, it is often used as a simplified language for growth rate.
Big-O hides constant factors and smaller terms so the main pattern is easier to see.
Core Idea
If an algorithm does about 3n + 10 basic operations, the important long-term pattern is linear growth, so it is described as O(n). If an algorithm checks every pair of elements, the main pattern is usually O(n^2).
Common growth rates include O(1), O(log n), O(n), O(n log n), O(n^2), and O(2^n).
Python Example
def print_pairs(values):
for left in values:
for right in values:
print(left, right)If values has n elements, the inner print runs n * n times. The time complexity is O(n^2).
Common Confusions
Big-O is not a measurement of exact runtime. It does not say how many milliseconds a program will take.
Big-O also does not automatically describe every case. A function can have one Big-O bound for its worst case and another for its best case.
Another common mistake is dropping the wrong variable. In graph algorithms, O(V + E) should not be simplified to O(n) unless n has been defined to include both vertices and edges.
When To Use It
Use Big-O when comparing algorithms at the level of growth. It is most useful when the input can become large enough that the growth pattern dominates small implementation details.