Are constants always irrelevant even if they are large?
For example is
O(10^9 * N) == O(N) ?
0
Big O describes how an algorithm scales; not, strictly speaking, how long it takes to execute.
In your example, if the time it takes to execute over 1 item is big, then it’s going to take a (non-trivially) long time to execute the algorithm, even if it’s applied to one item. But that algorithm will still increase in time linearly. So if you hit it with 100 items, you can expect it to take 100 times as long.
The same cannot be said of an O(n^2) algorithm; no matter how small the linear constant is, it’s still going to eventually overtake the time it takes to execute the linear algorithm (as you increase N).
The linear constant is therefore ultimately irrelevant.
2
It depends on what you are using your analysis to tell you.
-
If you are using it just to tell you how your algorithm scales up in the limit (i.e. as N goes to infinity), then the constants are not relevant.
-
If you are concerned (and you probably should be) with what the actual performance numbers are likely to be, then the constants are significant … and the lower order terms could be significant too.
Big O is a way of simplifying the complexity analysis to answer one performance-related question. There are other questions that are equally relevant.