Well, I figured it out →
Let's say we want to combine not 2 arrays, but r no arrays.
And let the total number of elements n
When merging, we will access the data elements from each array, and then compare with others to find out the minimum (for the ascending order) that will be added to the combined array.
The work done in comparison and finding the minimum value will be O (r). And since the total number of elements added to the combined array is n , So:
Complexity to merge r arrays with total elements n will be O(nr)
Applying the above result to Mergesort, where the array is divided into r smaller arrays each time
Since the array is each time divided into r smaller arrays, the process of division and merging will continue for log r n times.
So the complexity of such a Mergesort would be O (nrlog r n)
Now let's try to find out that for some given n, what value of r will make the least complexity. For this, the function F (r) = nrlog r n must be differentiated with respect to r and in the usual way found what is the value r = e (2.71) , which is not an integer. Also, the function begins to increase after this minimum point. Therefore, the integral value of r for which the complexity function is less than either 2 or 3 But (2nlog 2 n - 3nlog 3 n)> 0
So, the required value of r is 3
Therefore, Mergesort, dividing the array into 3 smaller ones, and then merging, should have the best mergesort .
Pradyumna sinha
source share