DEV Community

Discussion on: What does "Big-O notation" mean anyway?

Collapse
 
dwd profile image
Dave Cridland

Well, yes, or at least sort of. So if an algorithm takes a number of CPU cycles equal to (kn + c), then we call it O(n). For low values of n, the c may dominate, making it not a simple matter of linear scaling. But a typical algorithm has a low value of c.

So the case with 4 million inputs versus 8 million is really only working because the c is just noise at that level.

Luckily, c is going to be pretty small anyway, and much of it will remain constant no matter what the algorithm used - function call overheads, for instance.

Thread Thread
 
md2perpe profile image
Per Persson

An algorithm that is efficient for big n often takes more time for small n than one that is slow for big n. The reason is that the former is more complicated. Also, n is usually small.