2

I know that given O(n lg n) and O(n^2), (n lg n) is smaller when n is high enough.

But would O(n^2) be a correct evaluation of (n lg n)?

There is a big difference in O(n lg n) and O(n^2) so I'm not sure that O(n^2) would be the best answer to (n lg n)'s "worst case"

xenteros
  • 15,586
  • 12
  • 56
  • 91
Jules Mena
  • 67
  • 8
  • 1
    The question is not really well formed because people mean different things when they use "O", they most usually mean formal big thetha. And there is even less common way to define the meaning "is equal" in terms of big O notations. You should define which definition you go by. Here is a good read: http://stackoverflow.com/questions/471199/what-is-the-difference-between-%CE%98n-and-on – luk32 Sep 20 '16 at 12:55
  • [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – xenteros Aug 18 '17 at 08:24

2 Answers2

6

Answering the title question (which originaly was: Could you say that nlgn equals O(n^2)? ):

No, you can't as nlgn is a function and O(n^2) is a set.

Answering your question from the body:

Well, yes, nlogn is O(n^2)... but don't try to answer each question on the exam with O(n^n). It's not what they're asking. Big-O notation isn't used for giving the best answer. It's just a way of giving some information.

According to Wikipedia:

Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. It is a member of a family of notations invented by Paul Bachmann, Edmund Landau, and others, collectively called Bachmann-Landau notation or asymptotic notation.

xenteros
  • 15,586
  • 12
  • 56
  • 91
  • Great, thank you for the explanation. I will use "is" from now on. – Jules Mena Sep 20 '16 at 13:00
  • 3
    I'd like to mention one more sentence from wiki, which I find quite relevant: *"Informally, especially in computer science, the Big O notation often is permitted to be somewhat abused to describe an asymptotic tight bound where using Big Theta Θ notation might be more factually appropriate in a given context.[citation needed]"* – luk32 Sep 20 '16 at 13:00
1

xentros's answer is good. Another way to answer your question is that when Big-Oh asymptotics are requested, it's typically requested that you give as tight an upper bound as you can find.

So n lg n = O(n^2) (the = sign is an abuse of notation, but a common abuse); but it would be just as correct to say that n lg n = O(n lg n) and it would be better in the sense that it is a more restrictive upper bound.

Similarly, when you find a lower bound, the preference is for as large a lower bound as you can find. The really happy case is when you can find upper bounds low enough, and lower bounds high enough, to find a Theta bound.

Vatine
  • 20,782
  • 4
  • 54
  • 70
Patrick87
  • 27,682
  • 3
  • 38
  • 73
  • @Vatine In what way does this not answer the question? I read the question as "is n lg n = O(n^2)". The answer is "yes, but it's also O(n lg n) and that's a better answer". – Patrick87 Sep 21 '16 at 12:03
  • Honestly, I don't know why I picked that. :( I was looking at it and it must have not looked like an answer when I looked at it, but it does now. Let me see if I can make your answer a bit clearer. – Vatine Sep 21 '16 at 14:18