Assume that a mergesort algorithm in the worst case takes 30 seconds f...
Time complexity of merge sort is Θ(nLogn)
c*64Log64 is 30
c*64*6 is 30
c is 5/64
For time 6 minutes
5/64*nLogn = 6*60
nLogn = 72*64 = 512 * 9
n = 512.
Assume that a mergesort algorithm in the worst case takes 30 seconds f...
Explanation:
To solve this problem, we can use the concept of time complexity of mergesort algorithm which is O(n log n) in the worst case.
We know that the worst case time complexity of mergesort algorithm for an input of size n is given by:
T(n) = 2T(n/2) + n
where T(n/2) represents the time taken to sort half of the input size and n represents the time taken to merge the two halves of the input array.
Using this formula, we can find the time taken by mergesort algorithm for an input of size 64 in the worst case as follows:
T(64) = 2T(32) + 64
T(32) = 2T(16) + 32
T(16) = 2T(8) + 16
T(8) = 2T(4) + 8
T(4) = 2T(2) + 4
T(2) = 2T(1) + 2
T(1) = 1
Substituting the values of T(1), T(2), T(4), T(8), T(16), T(32) and T(64), we get:
T(2) = 4
T(4) = 10
T(8) = 22
T(16) = 46
T(32) = 94
T(64) = 190
Therefore, the worst case time taken by the mergesort algorithm for an input of size 64 is 190 seconds.
Now, we need to find the maximum input size of a problem that can be solved in 6 minutes (i.e. 360 seconds).
We can use the following formula to find the maximum input size:
T(n) = C * n * log n
where T(n) is the maximum time taken for an input of size n, C is a constant factor, and log n is the time complexity of the mergesort algorithm.
Substituting the values of T(n), C and log n, we get:
190 = C * 64 * log 64
C = 190 / (64 * 6)
C = 0.496
Now, we can use this value of C to find the maximum input size as follows:
360 = 0.496 * n * log n
n * log n = 725.81
n = 512 (approx.)
Therefore, the maximum input size of a problem that can be solved in 6 minutes is approximately 512.
Hence, the correct answer is option B.