A computer science portal for geeks


Quick sort V/S Heap sort

Home Forums Algorithms Quick sort V/S Heap sort

Tagged: ,

This topic contains 2 replies, has 3 voices, and was last updated by  Shekhu 4 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #79866


    I have read at many place that Quick sort is better than heap sort. I can’t understand why it is so as heap sort has guaranteed O(nlog(n)) while for quick sort there can be a worst case in which the order becomes O(n^2).



    Quick sort is not better than heap sort. It is just that the number of comparisons and exchanges required in Quick sort is much lesser as compared to Heap sort. If you take them as a comparison criteria then the you can Quick sort is better then heap sort



    Following are few lines from Wiki page of Quick Sort, these lines are relevant to the topic here.

    The most direct competitor of quicksort is heapsort. Heapsort’s worst-case running time is always mathcal{O}(n log n). But, heapsort is assumed to be on average somewhat slower than quicksort. This is still debated and in research, with some publications indicating the opposite.[11][12] In Quicksort remains the chance of worst case performance except in the introsort variant, which switches to heapsort when a bad case is detected. If it is known in advance that heapsort is going to be necessary, using it directly will be faster than waiting for introsort to switch to it.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.