n log n > n
-- but this is like a pseudo-linear
relationship. If n=1 billion
, log n ~ 30;
So n log n
will be 30 billion
, which is 30 X n
, order of n
.
I am wondering if this time complexity difference between n log n and n
are significant in real life.
Eg: A quick select
on finding kth element in an unsorted array is O(n)
using quickselect algorithm.
If I sort the array and find the kth element, it is O(n log n)
. To sort an array with 1 trillion
elements, I will be 60 times
slower if I do quicksort
and index it
.