3 ms·
The post is kind of misleading because it confuses "order of magnitude" with the order of a polynomial. To make this very clear: You have two functions, x^4 an
by alanctgardner2 13y ago
The post is kind of misleading because it confuses "order of magnitude" with the order of a polynomial. To make this very clear:
You have two functions, x^4 and x^3. You can multiply x^3 by any constant multiple a (any number, regardless of size), and as x gets sufficiently large x^4 will be bigger than a * x^3. This is the point of evaluating asymptotic performance: as your input data approaches an infinite size, only the highest order term in a polynomial really matters. For example, x^2 + x + 1 will approach x^2 for sufficiently large x - the lower order terms (x^1 and x^0) don't really matter for a big x.
Technically, big-O refers to a bounding function: x^2 is O(x^2) AND O(x^3), etc. because x^2 is less than or equal to x^2 and x^3 as you approach infinity. For convenience we're usually only interested in the best fit; it's useless to say your algorithm is faster than O(x^5), but it's interesting if it's O(n).
Finally, we also have small-oh notation, which is a lower bound. If your algorithm is never faster, on an ideal input set, than x^2, it's also o(x^2). Note that the same algorithm is also o(n) and o(1), because any algorithm which is slower than (or equal to) x^2 must necessarily be slower than x or 1 (constant-time).
edit: It's worth pointing out I only talked about polynomials because it's pretty intuitive. You can extend this notation to any class of functions - exponentials, logarithms, etc. but you just have to know that log(x) is O(x) and o(1), etc.
- repsilat 13y ago> Finally, we also have small-oh notation, which is a lower bound. Little-oh is a strict upper-bound. If `f` is `o(g)` then lim_(x -> inf) f(x)/g(x) -> 0. Or something. It has been a while. If you want an asymptotic lower-bound you want big Omega (non-strict) or little omega (strict).