Which is better: O(n log n) or O(n^2)

Just ask wolframalpha if you have doubts.

In this case, it says

     n log(n)
lim --------- = 0
       n^2

Or you can also calculate the limit yourself:

     n log(n)        log(n)   (Hôpital)       1/n          1
lim --------- = lim --------      =     lim ------- = lim --- = 0
       n^2             n                       1           n

That means n^2 grows faster, so n log(n) is smaller (better), when n is high enough.

Leave a Comment