I think the first thing to pay attention to this problem is that since it took 4 minutes to sort the numbers, n should be pretty big. For example, I just used quicksort to sort a billion numbers on my computer, and it took less than 3 minutes. So n is probably about 1 billion (give or take order).
Given that n is huge, it is likely that this runtime will correspond to c*n*lg(n) for some constant c , since conditions of a lower order of extension of execution should not be too relevant for such a large n . If we double n , we get the following runtime factor compared to the original runtime:
[Runtime(2n)] / [Runtime(n)] [c * (2n) * lg(2n)] / [c * n * lg(n)] 2 * lg(2n) / lg(n) 2 * log_n(2n) 2 * (1 + log_n(2))
Here lg() is the logarithm under an arbitrary base, and log_n() is the log base n .
First, since we assumed that n large, one possible way to continue would be to approximate log_n(2) as 0, so the runtime factor would be approximate as 2, and the total duration would be approximate as 8 minutes.
Alternatively, since we probably know n up to an order of magnitude, another possibility would be to approximate the multiplier for the probable value of n :
- If
n = 100 million, then we will approximate the factor as 2.075, and the total execution time is 8.30 minutes. - If
n = 1 billion, then we will approximate the factor as 2.067, and the total execution time is 8.27 minutes. - If
n = 10 billion, then we would approximate the multiplier as 2.060, and the total lead time is 8.24 minutes.
Note that the huge changes in our approximation n give fairly small changes in the approximation of the total execution time.
It is worth noting that, although this looks good on paper, in practice, architectural considerations can lead to the fact that the actual battery life will be very different from those that we calculated here. For example, if the algorithm causes a bunch of paging after doubling the size of the data, the execution time can be much longer than the approximately 8 minutes we approximated here.
josliber
source share