Just started learning algorithms. So the exercise is to find if statement is always/sometimes true or false. Em, where does my logic fails here?
f(n) != O(g(n)) and g(n) != O(f(n))
O-notation is 0 <= f(n) <= cg(n) where c is some constant. So not equal here means:
f(n) > cg(n) and g(n) > cf(n)
If f(n) = g(n) = 1, and let’s say c = 1/2:
1 > (1/2)*1 and 1 > (1/2)*1
So it is true in this case. But the book says it’s false in this particular case. What part do I misunderstand?
Big-O is not
0 <= f(n) <= c g(n)for some constant, per se. It’s that there exists a number c such that the relation holds for “large enough” values of n. (This is the “asymptotic” that we refer to when we call Big-O an asymptotic notation, the other common ones being Big-Theta and Big-Omega.)For example, let’s say there’s an algorithm that operates on some data structure with
nelements, and takes3n^2 + 7n + 18steps. Call thisf(n). We say that the Big-O of this expression isO(n^2)because there exists a constant (in this case anything larger than 3) such that for all “large enough” values ofn,f(n) <= c n^2.