Skip to content
IT glossary
AlgorithmsUpdated December 3, 2026

Big O

Big O puts an upper bound on how quickly an algorithm’s time or memory needs grow as its input gets larger.

Also known as: О-большое, асимптотическая сложность

What Big O tells you

Suppose a program needs to find a name in a list. If the names are in no particular order, the program may have to check all n entries. If they're sorted in an array, binary search can eliminate about half of the remaining entries with each comparison. The worst-case comparison counts are O(n) and O(log n), respectively. Big O describes how those counts scale, not how many milliseconds either search takes.

What an upper bound means

We write f(n) = O(g(n)) if there are constants C > 0 and n₀ such that f(n) ≤ C · g(n) for every n ≥ n₀. In other words, once the input is large enough, a fixed multiple of g(n) is enough to bound the cost. That is why 4n² + 20n + 7 is O(n²): the quadratic term determines the growth, and the leading coefficient can be absorbed into C.

An upper bound need not be tight. The same quadratic function is also O(n³), but that tells you less. Use Θ(n²) when you want to say that the function grows at the quadratic rate, bounded both above and below by constant multiples of n² for sufficiently large n.

Example: checking every distinct pair

 def count_equal_pairs(items):
     count = 0
     for i in range(len(items)):
         for j in range(i + 1, len(items)):
             if items[i] == items[j]:
                 count += 1
     return count

The first outer iteration checks n − 1 pairs, the next checks n − 2, and the last checks none. That adds up to n(n − 1)/2 comparisons. With constant-time comparisons and counter updates, the runtime is Θ(n²). The function counts pairs without storing them, so it uses O(1) auxiliary space in the usual model where an index or counter fits in a machine word.

Where it helps and where it doesn't

Growth rates help you choose a data structure or spot work that will get expensive as inputs grow. They don't tell you where one implementation overtakes another. A linear scan can win on a short list, and binary search may not be worthwhile for a single lookup if you have to sort the input first. Benchmark when that crossover matters.

Big O also doesn't mean “worst case.” It can bound the cost of whichever case you've defined. Linear search is O(1) in the best case, when the first entry matches, and O(n) in the worst case, when the match is last or missing.

How to explain it in an interview

Define the input sizes, name the operation you're counting, and explain how often it runs. Two consecutive passes over the same n entries take O(n) time in total if each visit does constant work. Comparing every entry in one collection with every entry in another takes O(nm) under the same assumption: keep n and m separate unless the problem relates them. Give time and auxiliary space bounds separately.