Suppose
S(n) = Big-Oh(f(n)) & T(n) = Big-Oh(f(n))
both f(n)
identically belongs from the same class.
My ques is: Why S(n)/T(n) = Big-Oh(1)
is incorrect?
Suppose
S(n) = Big-Oh(f(n)) & T(n) = Big-Oh(f(n))
both f(n)
identically belongs from the same class.
My ques is: Why S(n)/T(n) = Big-Oh(1)
is incorrect?
You can prove that this is wrong if you plug some actual functions into your formula, e.g.
Consider
S(n) = n^2
andT(n) = n
. Then bothS
andT
areO(n^2)
butS(n) / T(n) = n
which is notO(1)
.Here's another example. Consider
S(n) = sin(n)
andT(n) = cos(n)
. ThenS
andT
areO(1)
butS(n) / T(n) = tan(n)
is notO(1)
. This second example is important because it shows that even if you have a tight bound, the conclusion can still fail.Why is this happening? Because the obvious "proof" completely fails. The obvious "proof" is the following. There are constants
C_S
andC_T
andN_S
andN_T
wheren >= N_S
implies|S(n)| <= C_S * f(n)
andn >= N_T
implies|T(n)| <= C_T * f(n)
. LetN = max(N_S, N_T)
. Then forn >= N
we haveThis is completely and utterly wrong. It is not the case that
|T(n)| <= C_T * f(n)
implies that1 / |T(n)| <= 1 / (C_T * f(n))
. In fact, what is true is that1 / |T(n)| >= 1 / (C_T * f(n))
. The inequality reverses, and that suggests there is a serious problem with the "theorem." The intuitive idea is that ifT
is "small" (i.e., bounded) then1 / T
is "big." But we're trying to show that1 / T
is "small" and we just can't do that. As our counterexamples show, the "proof" is fatally flawed.However, there is a theorem here that is true. Namely, if
S(n)
isO(f(n))
andT(n)
isΩ(f(n))
, thenS(n) / T(n)
isO(1)
. The above "proof" works for this theorem (thanks are due to Simone for the idea to generalize to this statement).Here's one counter example:
Let's say
f(n) = n^2
,S(n) = n^2
andT(n) = n
. Now both S and T are inO(f(n))
(you have to remember thatO(n^2)
is a superset ofO(n)
, so everything that's inO(n)
is also inO(n^2)
), butU(n) = S(n)/T(n) = n^2/n = n
is definitely not inO(1)
.Like the others explained S(n) / T(n) is not generally O(1).
Your doubt probably derive from the confusion between O and Θ; in fact if:
then the following is true: