Question about sorting algorithms:
If I call quickselection function within heapsort algorithm, does that mean that the complexity will me smaller?
Printable View
Question about sorting algorithms:
If I call quickselection function within heapsort algorithm, does that mean that the complexity will me smaller?
I assume by quickselect you mean the partitioning method found in quicksort that partially reorders the array to give you the kth smallest item in the kth position.
If so, no there is no way to use that to improve the time or space complexity of heapsort. It moves items, which would destroy the heap property.
Heapsort is already best case for a comparison based sorting algorithm. It just has a higher constant factor than some other algorithms.
I want to call quickselect (or partitioning) before the heapsort.
And the aim of all that is to change the complecity of the algorithm from nlogn to n+clogn.
What do you think? Am I stretching this?
Oh, you're stretching it, alright! :p
Partitioning before the heapsort, will hurt, not help, your sorting with Heapsort. You're just wasting time doing it.
There is nothing that you can do prior to calling heapsort that can redice the total time taken, or change the time complexity of HeapSort.
HeapSort is O(n*log n) in worst case, average case, and best case.
The only thing I've seen that speeds up HeapSort is using a fibonacci heap or weak heap instead of a binary heap. Though in either case it's then a different and much more complicated algorithm.