How to prove big-o relations
Hey, the title is probably a bit off, so please correct it if you know how to put it better.
As a homework assignment I have been given several assignments along the following:
Let f(n) and g(n) be asymptotically positive functions. Prove or disprove each of the following conjectures.
a. f(n) = O(g(n)) implies g(n) = O(f(n))
Now, my real question is - how would you go about proving this in a formal way? I know that the above would be easy as I could easily provide a counter example to disprove it, but for the sake of the argument let's say that we want to do this without counter examples, as of course this continues on with some other examples where this will not work.
I am a bit stuck, I have the following inequalities written up (with <= being less than or equal to)
f(n) <= c1 * g(n)
g(n) <= c2 * f(n)
But I am uncertain of how I would combine these 2 inequations into a single (in)equation and disprove it. I am most certain that this is something quite easy that I have simply overlooked and that I am being rather stupid at the moment - but any pointers / concr开发者_Python百科ete examples of how to do this would be great, so that I should be able to work the rest of these questions out on my own.
Why do you want to disprove it without using a counterexample? That is the most direct way to disprove a claim.
If you had to prove it instead, of course you would not be able to use a counterexample. In this case, contrapositive can work very well - assume that the claim is false, and then show how that leads to a logical inconsistency.
In this case, you start with f(n) <= c1 * g(n)
being true, since this is what is meant by f(n) = O(g(n))
. Now you want to assume that g(n) <= c2 * f(n)
is true for all f
and g
(this last part is very important, because you can certainly pick f
and g
such that it is true), and show why this can't work. My hint for you: pick an f
and a g
such that it can't work, and show that it can't work by your choice of c1
and c2
.
A few hints:
Don't forget that f(n) = O(g(n))
is a set notation and you can convert it to a mathematical form of inequalities.
Simple operations you can do with the O-notation:
f(n) = O(f(n))
c * O(f(n)) = O(f(n))
, if c is constantO(f(n)) + O(f(n)) = O(f(n))
O(O(f(n))) = O(f(n))
O(f(n)) * O(g(n)) = O(f(n)g(n))
O(f(n)g(n)) = f(n) * O(g(n))
(The Art of Computer Programming, vol 1 - The O-Notation)
精彩评论