سؤال

This is a problem on Asymptotic Notation from the assignment of MIT OpenCourse Introduction to Algorithm:
For each of the following statements, decide whether it is always true, never true, or sometimes true for asymptotically nonnegative functions f and g. If it is always true or never true, explain why. If it is sometimes true, give one example for which it is true, and one for which it is false.

f(n) ≠ O(g(n)) and g(n) ≠ O(f(n))   (both are Big-O notes)

I think it is never true. Here's my proof:

   f(n) ≠ O(g(n))
=> f(n) = w(g(n))   (little-omega note)
=> g(n) = o(f(n))   (little-o note)
=> g(n) = O(f(n))   (big-O note)

the result contradicts to g(n) ≠ O(f(n)) (Big-O note). Likewise,

   g(n) ≠ O(f(n))
=> g(n) = w(f(n))   (little-omega note)
=> f(n) = o(g(n))   (little-o note)
=> f(n) = O(g(n))   (big-O note)

which contradicts to f(n) ≠ O(g(n)) (Big-O note).

The solution says it is sometimes true:

For f(n) = 1 and g(n) = ||n*sin(n)|| it is true,  
while for any f(n) = O(g(n)), e.g. f(n) = g(n) = 1, it is not true.

Where have I done wrong in my proof? Also, I cannot understand the solution. ||n*sin(n)|| looks like vector norm to me.

هل كانت مفيدة؟

المحلول

The first is not true : from this f(n) ≠ O(g(n)) it does not follow this: f(n) = w(g(n)). The two functions might intersect at some point and then slap places, the other becoming bigger (if I use simple words).

The function they chose is just this case: for n <= 1 the first f(n) > g(n) and there exist ns for which g(n) > f(n) (e.g pi / 2).

نصائح أخرى

I think n*sin(n) just shows that it is a function which keeps getting larger & smaller than f(n) = 1 for subsequent values of n even for all choices of a constant multiplier used for defining Big O & thus f(n) ≠ O(g(n)) and g(n) ≠ O(f(n))

A Naively chosen function like g(n) = 2*sin(n) won't do good here. One might think that this would also keep alternating around f(n) = 1 , but g(n) = O(f(n)) : M*f(n) > g(n) for M = 3 etc

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top