0

I'm trying to figure out the efficiency of my algorithms and I have little bit confusion. Just need some expert idea to justify my answers or reference me to somewhere which is explaining about the being an element of not in asymptotic subject. (There is many resources but nothing about element of set is found by me)

When we say O(n^2) which is for two loops is it right to say:

n^2 is an element of O(n^3)

To my understanding big O is the worst case and omega is the best efficient case. If we put them on the graph all the cases of n^2 is part of O(n^3) so the first one is not right?

n^3 is an element of omega(n^2)

And also about the second one it is not right. Because some of the best cases of omega(n^2) is not in all the cases of n^3!

Finally is

2^(n+1) element of theta(2^n)

I have no idea how to measure that!

Bernard
  • 4,240
  • 18
  • 55
  • 88
  • the last statement is easy: `2^(n+1) = 2 * 2^n = theta(2^n)` as constant linear factors are abstracted away. otherwise `O` is a particular notation with an accompanying definition - it is possible to phrase the definition such that `O` describes a set of functions. however, `f(n) = O(g(n))` is in common usage and can be as rigorously defined as the set-theoretic approach. – collapsar Aug 21 '13 at 10:37
  • Even simpler: if `lim (n->INF) f(n)/g(n) = non-zero constant` then f(n) = Θ(n*n). If it goes to 0 or infinity, it can still be in O or Ω; if the limit does not exist you have an issue. – MSalters Aug 21 '13 at 10:51

2 Answers2

4

Big O, omega, theta in this context are all complexities. It's the functions with those complexities which form the sets you're thinking of.

Indeed, the set of functions with complexity O(n*n) is a subset of those with complexity O(n*n*n). Simply said, that's because O(n*n*n) means that the complexity is less than c*n*n*n as n goes to infinity, for some constant c. If a function has actual complexity 3*n*n + 7*n, then its complexity as n goes to infinity is obviously less than c*n*n*n, for any c.

Therefore, O(n*n*n) isn't just "three loops", it's "three loops or less".

Ω is the reverse. It's a lower bound for complexity, and c*n*n is a trivial lower bound for n*n*n as n goes to infinity.

The set of functions with complexity Θ(n*n) is the intersection of those with complexities O(n*n) and Ω(n*n). E.g. 3*n doesn't have complexity Θ(n*n) because it doesn't have complexity Ω(n*n), and 7*n*n*n doesn't have complexity Θ(n*n) because it doesn't have complexity O(n*n).

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Thanks heaps, your answer really helped me to better understanding of complexity but I'm so weak in mathematical stuff and trying to learn more. When we say (n*n) ∈ O(n*n*n) I imagine a graph with x and y. function (n*n) is a line and function (n*n*n) is a line. O(n*n*n) is everywhere on the graph left side of its line until infinity. right? Now assume for (n*n), x=2 then y=4 and for (n*n*n) x=2 then y=8. Therefore O(n*n*n) doesn't cover some part of (n*n) which is (2,4). hope I could explain clearly. Could you please tell me where is my mistake? – Bernard Aug 21 '13 at 11:09
  • 1
    No. First off, we were using `n` instead of `x`, that's just a convention. `n*n` or `x*x` is a parabola. All lines are `a*x+b`. Furthermore, the whole "as n goes infinity" means that we look where the functions are heading in the far right of the graph. Finally, even the "smallest" set Θ(n*n) covers ALL parabola. So not just `n*n` but also `2*n*n` and `100000 * n * n`. We consider that smaller than even `0.001 * n * n * n`. After all, n goes to infinity, so after n>100000000 the latter is bigger. – MSalters Aug 21 '13 at 12:44
2

I will list the answers one by one.

1.) n^2 is an element of O(n^3)
True
To know more about Big-Oh read here.

2.) n^3 is an element of omega(n^2)
True
To understand omega notation read here.

3.) 2^(n+1) element of theta(2^n)
True
By now you would know why this is right.(Hint:Constant factor)

Please ask if you have any more questions.

Community
  • 1
  • 1
Aravind
  • 3,169
  • 3
  • 23
  • 37