The best example of N * log (N) , in my opinion, would be to search for a comparison based search:
Let's take merge-sort as an example.
The algorithm takes an array of elements, splits it into 2 recursively, until it gets an array of length 2, and then combines the parts in O (n), each merging of sorted arrays is easier.
Ok, that was a short description, now let's see what it looks like:
[ 1 2 3 4 5 6 7 8 ] | /\ [1 2 3 4] [ 5 6 7 8 ] | | /\ /\ [1 2 ] [ 3 4] [5 6] [7 8]
I hope you can see here that the recursion depth is log (n) (because it is a tree that has 2 branches ... so log (n) with base 2)
But at every level of the tree, there are O (n) operations (because we are actively rebuilding the n object).
So here N * log (N) is complicated.
Most algorithms that have Log (N) complexity get this from the tree algorithm.
There are a few that are just probabilistic log (n) (which means that after a long mathematical calculation you get that on average it will be something like log (n))
source share