Consider the following variation of mergesort: (a) If n ≤ 1, we are done. (b) Divide the n elements into b subarrays of n/b elements each. (c) Recursively call mergesort to sort each of the b subarrays. (d) Merge the b sorted subarrays. For example, the standard mergesort has b = 2, and merging takes Θ(n) comparisons. If b = 3, then we have a 3-way mergesort, and one can show that it takes Θ(n) comparisons to merge 3 sorted lists. In fact, one may show that merging b sorted lists (for any fixed b) can be done in Θ(n) comparisons. Now consider the following argument: if we set b = n, we recursively sort n subarrays of size 1, and then merge them into one list with Θ(n) comparisons. Thus, the complexity can be expressed by: T(1) = 0 T(n) = nT(1) + Θ(n) = Θ(n) Therefore, this variation of mergesort sorts an array in Θ(n) comparisons. What is wrong with this argument? Hint: think about how to implement this variation.
Consider the following variation of mergesort:
(a) If n ≤ 1, we are done.
(b) Divide the n elements into b subarrays of n/b elements each.
(c) Recursively call mergesort to sort each of the b subarrays.
(d) Merge the b sorted subarrays.
For example, the standard mergesort has b = 2, and merging takes Θ(n) comparisons.
If b = 3, then we have a 3-way mergesort, and one can show that it takes Θ(n) comparisons to merge 3 sorted lists. In fact, one may show that merging b sorted lists (for any fixed b) can be done in Θ(n) comparisons.
Now consider the following argument: if we set b = n, we recursively sort n subarrays of size 1, and then merge them into one list with Θ(n) comparisons. Thus, the complexity
can be expressed by:
T(1) = 0
T(n) = nT(1) + Θ(n) = Θ(n)
Therefore, this variation of mergesort sorts an array in Θ(n) comparisons.
What is wrong with this argument? Hint: think about how to implement this variation.

Step by step
Solved in 3 steps









