Asymptotic Analysis — Big-O, Growth & the Cost Model

why we use asymptotic analysis

Imagine two cooks racing to chop vegetables. One has a slightly faster knife, the other a slightly slower one. For three carrots, the knife barely matters. But ask them to chop ten thousand carrots and the difference in their method, not the knife, decides the winner. Asymptotic analysis is the habit of asking the same question about algorithms: not how fast a program runs on one machine for one input, but how its running time grows as the input gets bigger and bigger.

The idea is to express the cost as a function of the input size n, and then keep only what governs that function for large n. We deliberately throw away two kinds of detail. First, constant factors: if one method does 5n steps and another does 100n steps, both grow linearly, and we say both are 'order n', because hardware speed, language, and compiler can swallow constant factors anyway. Second, lower-order terms: a cost of n^2 + 3n + 7 is dominated by the n^2 part once n is large, since for n = 1000 the n^2 term is a million while 3n + 7 is barely three thousand. So we report n^2 and drop the rest. What remains is the shape of growth.

This matters because it makes a prediction that survives a change of computer, programming language, or input. An algorithm that grows like n^2 will eventually lose to one that grows like n log n, no matter whose laptop you run it on, simply because the gap widens without bound as n grows. The honest caveat is that asymptotics describe scaling, not a verdict at every size: for small n the dropped constants and low-order terms can completely reverse the ranking, which is exactly why we say 'eventually'.

Method A does 100n basic steps; method B does n^2 steps. At n = 10, A does 1000 steps and B does only 100, so B wins. At n = 100 they tie at 10000. At n = 1000, A does 100000 but B does 1000000, so A wins by 10x; at n = 1,000,000 A wins by 10000x. The crossover at n = 100 is exactly where the dropped constant stops mattering.

Constants decide the small-n race; growth rate decides the large-n race.

Asymptotic analysis predicts how cost scales, not which algorithm is fastest on your actual input; for small n a 'worse' asymptotic method can be the practical winner.

Also called
asymptotic analysis漸進分析