Constant Factors and Scaling
Two procedures can have the same growth class and different costs at sizes that an application actually sees.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Calculate a crossover
If procedure A costs \(2n+100\) units and B costs \(5n+10\), both cost \(\Theta(n)\). Their costs match at \(n=30\). A's fixed start makes it more expensive at small sizes. Big-O upper bounds omit both constants in the class.
Measure the usual operation
Real inputs may make constants vary through memory behavior or branching. Choose units that reflect the application and check the observed cases. See empirical scaling for comparisons using several sizes.[1]
Compute where two simple cost models cross
Suppose method A costs \(12n\) units and method B costs \(n^2\) units under a fixed operation model. At \(n=6\) B costs thirty-six and A costs seventy-two. At \(n=30\), A costs three hundred and sixty while B costs nine hundred. See big-O bounds.
n A = 12n B = n²
6 72 36
12 144 144
30 360 900
Test the range the product will actually encounter
The crossover in this hypothetical model is twelve for positive sizes. Measuring real code requires representative inputs and a clear operation or time unit. Include setup costs where callers perform them each time and throughput when one setup serves many requests.