Hacker News new | past | comments | ask | show | jobs | submit login

He's saying that big O only matters for big input sizes, because big O is specifically about the algorithm's asymptotic performance, which means its performance for a large value of n. If you have a small value of n then the other constant time operations in the algorithm may affect the running time more.

n^2 is less than n^3 right?

But is 2 * n^2 + 100 less than n^3?

Depends on how big n is, right?

Big O notation just assumes that n is big enough to make the answer "yes."




More or less, yes. What he is saying is that there is a constant hidden in the big O. Say, we have two algorithms A and B with a runtime that can be bounded by the functions a(n) = 1000n^2 and b(n) = 0.001n^3 respectively. Hence a ∈ O(n^2) and b ∈ O(n^3). So the first algorithm A is clearly faster asymptotically. However, suppose we have input sizes of around n=50000, it actually turns out that algorithm B is faster because g(50000) < f(50000). This is because of the constant that is hidden in the big O. For sufficiently large n however (n > 10000000 in this case), algorithm A will always be faster.

A good implementation could check problem sizes beforehand and chose the algorithm accordingly.

What I don't agree with is that "big O only matters for big input sizes". Big is not really a well-defined term. The problem here is that "big" depends entirely on the algorithms. It might also be n > 10. There's nothing in the definition of the landau symbols that prevents that.


The definition of a "big" input size is somewhat circular, yes.

"The big O performance of an algorithm only matters for a sufficiently large value of n."

"Define a sufficiently large value of n."

"Large enough that the big O performance of the algorithm starts to matter more than the coefficients of n and constant time operations."

So yes, that could be 10 or 10 million depending on the nature of the problem, the constants and coefficients of the algorithm, the language, the hardware, etc etc. You could have an algorithm that takes factorial time but maybe you're only using it in a problem ___domain where n is always < 10 so you'll probably never notice or care that it's O(n!)




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: