BelowHere is a variation of quick-sort where-in the pivot selection is based on calculating the average of the values of the highest and lowest numbers.
The belowThis approach performs a pass on every iteration to determine the high and low values.
My understanding is that this approach requires a maximum of \$2*n*\log_2(n)\$\$2 \cdot n \cdot \log_2(n)\$.
Eg: 1,2,3,4,5,6,7,8.
Example: 1,2,3,4,5,6,7,8.
Eg: 1,2,4,8,16,32,64,128,256,512....
Example: 1,2,4,8,16,32,64,128,256,512....
However, given that numbers are typically represented as byte (8), short (16), int (32), long (64), for a given datatype - Ege.g.: integer, the maximum number in the worst case sequence would be : 2,147,483,648. So basically for an integer datatype, the sequence - 1,2,4,8,16,..., would reach a maximum of 2,147,483,648 after 30 steps after which the sequence must repeat.
1,2,4,8,16,32,64,128,256,1,2,4,8,16,32,64,128,256,1,2,4,8,16,32,64,128,256,..
1,2,4,8,16,32,64,128,256,1,2,4,8,16,32,64,128,256,1,2,4,8,16,32,64,128,256,...
simply because the byte can't hold more than 256 (unsigned)...
As such in case of worst case input as well, the approach : (high+low)/2 would still only have to deal with a depth of log2(n)\$log_2 n\$ because the numbers would repeat.
Although above would not hold where the number of elements in the array is small compared to the datatype itself... Ege.g.: 10% of the total capacity, where in it's still possible to induce worst-case scenarios for the given data-set, for data-sets with sizes comparable to the maximum value supported by the data-type, the approach would work.
What is less clear is : Given
Given that the best-case scenario is in \$\mathcal{O}(n*\log_2(n))\$\$\mathcal{O}(n \cdot \log_2(n))\$, and given that for worst-case scenarios, for data-sets with sizes comparable to the maximum value the datatype also the scenarios appears to be \$n*\log_2(n)\$\$n \cdot \log_2(n)\$, is it true for average-case scenario as well?
From what I can tell, it's true and as such the entire approach is in \$\mathcal{O}(n*\log_2(n))\$\$\mathcal{O}(n \cdot \log_2(n))\$.
However, I need confirmation on the approach, understanding and the conclusion!.
Below is a code snippet implemented in java.
PS: Have blogged about the algorithm previously - in around 2013.
Basically, the goal is to determine whether it's comparable to the median-of-three approach that java uses in its Arrays.sort() implementation.
In
In test-cases cases that I've run, it appears to be comparable to the time taken by the median-of-three algorithm - even for random data-sets sets. So, I want to know if the concept holds good as well or if it's just by chance and there is a data-set set where the median-of-three is better than this approach.