4

I was doing this quiz on an online course and one question stated;

The function nlogn + √n + 5 may set to belong to
A: nlogn
B: √n
C: n√n

The quiz said the correct answer is A, but isn't square root of n slower? I am new to finding the time complexity of an algorithm and could use an explanation. Or let me know if the answer is wrong.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Grez.Kev
  • 247
  • 1
  • 6
  • 17

3 Answers3

5

You should consider n to be an extremely large number. For any n>2, n>√n and logn>1. Thus, nlogn>√n.

takendarkk
  • 3,347
  • 8
  • 25
  • 37
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

The correct Hierachy is this:

Superlinear[ n log n] > Linear [n] > sub polynomial [n^(1/a)]

Where a: a >= 1.

Thus n log n = O(n) = O(sqrt(n))

N does not need to be an 'Extremely large number" though Big-Oh deals with limits to infinity. In particular, you can set your n0 as `b+Where b is the base of the logarithm. In this case 10.

Test with n=11 yourself to find out.

Tobi Alafin
  • 269
  • 2
  • 13
0

Yes, √n is surely more than logn. (cf)

But you're multiplying that logn with n.

n is obviously more than √n.

(If you would multiply √n with n too, then the answer is n√n.)

Pacerier
  • 86,231
  • 106
  • 366
  • 634