Suppose company X has created 3 new variants of quicksort but, because they are
ID: 3751421 • Letter: S
Question
Suppose company X has created 3 new variants of quicksort but, because they are unsure which is asymptotically best, they have hired you to analyze their runtimes. Compute the asymptotic runtimes of the variants and use this to justify which is best:
a) Variant 1: Partitioning the array still takes (n) time but the array will always be divided into a n x and (x1)n x portion (where x is some constant value > 1).
b) Variant 2: Partitioning the array now takes (n1.1) time but the array will always be divided perfectly in half. c)
c) Variant 3: Partitioning the array now only takes (n) time but all of the numbers except the pivot will be partitioned into a single array.
Reminder: logn o(nc) for all c > 0.
I need help please!!!
Explanation / Answer
The asymptotic runtimes of the given three variants are as follows:
For the 1st Variant:
Explanation:
The array partition takes O(n) time.
Since, the array is subdivided into 10%, and 90%, so the array is subdivided into n/10 and 9n/10 respectively.
Therefore, the recurrence relation as per the given variant is as follows:
T(n) = O(n) + T(n/10) + T(9n/10)
Hence, while solving the above recurrence relation, the resultant asymptotic complexity is as follows:
T(n) = O (n log n)
The resultant complexity is equal to the average time complexity of the quick sort.
For the 2nd Variant:
Explanation:
Since, the array is divided into the two halves therefore, the size of the array becomes n/2.
The problem is divided into two halves therefore it results to 2T(n/2).
Also, the time taken to partition the array is O(n).
Therefore, the recurrence relation as per the given variant is as follows:
T(n) = 2T(n/2) + O(n)
Hence, while solving the above recurrence relation, the resultant asymptotic complexity is as follows:
T(n) = O (n log n )
The resultant complexity is equal to the average time complexity of the quick sort.
For the 3rd Variant:
Explanation:
In this case, the array is divided in such a way that the one part of the array consists of only one element, and the second part comprises of the rest of the other elements of the array.
Therefore, for the size of array 1, T(n) =1 which is a constant value that can be ignored.
And, the size of the rest of the array is T(n-1).
The array partition takes O(n) time.
Therefore, the recurrence relation as per the given variant is as follows:
T(n) = T(n-1) + O(n)
Hence, while solving the above recurrence relation, the resultant asymptotic complexity is as follows:
The resultant complexity is equal to the worst-case time complexity of the quick sort.
Thus, the best case asymptotic complexity is O (n log n).
Since, it takes lesser time as compared to the complexity of the third variant for any value of n.