By repeating the above pattern, we shall arrive at the following relation:
NumComp (N) = 8 NumComp(N/8) + 3N = 2
3
NumComp(N/2
3
) + 3N (3.3)
We can generalize the above relation as:
NumComp (N) = 2
k
NumComp(N/2
k
) + kN (3.4)
The merge sort stops when we are left with one element per partition, i.e., when N= 2
k
.
Now for N = 2
k
or k = log
2
N, we can rewrite Eq. 3.4 as:
NumComp (N) = N NumComp(N/N) + N
*
log
2
N
= N NumComp(1) + N
*
log
2
N = N
*
0 + log
2
N
*
N = N
*
log
2
N
= N
*
log
2
N
Thus, T(N) = N
*
log
2
N <= C*N
*
log
2
N + n
0
T(N) = O(N
*
log
2
N) for c = 1 and n
0
= 0
Thus, the time complexity of merge sort is of the order of N
*
log
2
N or ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.