-2

i'm looking at time complexity; and i want to ask, is O(log n) the best run time when comparing to O(n log n), O(n) and O(n square)? and if so, why?

Eddie Vu
  • 65
  • 1
  • 8
  • Are there any positive integer values of `n` where `log n` is larger than those other ones? – David Aug 27 '18 at 09:38
  • Possible duplicate of [Compare Big O Notation](https://stackoverflow.com/q/11940730/11683) – GSerg Aug 27 '18 at 09:39
  • Possible duplicate of [Do you use Big-O complexity evaluation in the 'real world'?](https://stackoverflow.com/q/1248509/11683) – GSerg Aug 27 '18 at 09:39
  • Possible duplicate of [Slowest Computational Complexity (Big-O)](https://stackoverflow.com/q/16388759/11683) – GSerg Aug 27 '18 at 09:41
  • For small enough `n`, big O has nothing to do with the actual runtime. – Ben Jones Aug 27 '18 at 16:23

1 Answers1

0

When you talk about time complexity you have to consider the fact that everything is considered for n→ + ∞. Therefore if you look at the graph of the functions you mentioned enter image description here

you can clearly see that as x (= n) increases, the time (y axis) grows a lot of slower for log(x) respect to the other functions.

Marco Cadei
  • 145
  • 2
  • 4
  • 14