can someone please explain exactly what a dual sort algorithm is and how it works? I’ve searched the web and haven’t been able to find any info on it. I have a homework assignment where im suppose to explain what it is and write a program that sorts a list using dual sort.
Thanks for any help!
A dual pivot quick sort has the idea of 2 pivots and is very similar to a regular quick sort. There are a few variants of choosing the pivots put lets assume a random choice, than the algorithm would be something like the following (I won’t give explicit code since it is still homework after all). The essential idea is to pick random pivots p1 and p2. Assume p1 <= p2 otherwise swap their values. Now order the array into three parts. The first will be less than p1, the second is elements between or equal to p1 and p2, the third is elements larger than p2. Than recurse on each part.
Asymptotically, as you might guess knowing a sort of O(n lg n) is optimal, this algorithm runs in the same time as quick sort.