Perhaps a good start is to look at the recurrence ratio for this problem. I assume that for a typical mergesort it will look something like this:
T(N) = 2 * T(N / 2) + N
i.e. you divide the problem into 2 subtasks equal to half the size, and then do the N-job (merge). We have a base case that takes constant time.
Modeling this as a tree, we have:
T(N) = N -> T(N / 2)
-> T(N / 2)
= N -> (N / 2) -> T(N / 4)
-> T(N / 4)
-> (N / 2) -> T(N / 4)
-> T(N / 4)
It gives decomposition
T(N) = N + 2N/2 + 4N/4 + ...
= N + N + N ...
So we really need to see how deep this is happening. We know that the inth level works by subtask N / 2^iby size. Therefore, our leaf nodes ( T(1)) are found at a level Lwhere N / 2^L = 1:
N / 2^L = 1
N = 2^L
log N = log(2^L)
log N = L
Thus, our runtime N log N.
Now we introduce insertion sort. Our tree will look something like this.
T(N) = ... -> I(K)
-> I(K)
...x N/K
, - L N/K K. K^2. , :
(N / K) * I(K)
= (N / K) * K * K
= N * K
, , N , . , L ( , K , , ):
N / 2^L = K
N / K = 2^L
L = log (N/K)
,
O(N) = N * K + N * log (N/K)
, , , .