GeeksforGeeks

A computer science portal for geeks

GeeksQuiz

Login

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 3 years, 7 months ago.

  • Author
    Posts
  • #79866

    Anonymous

    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).

  • #104469

    Vick
    Participant

    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

  • #104470

    Shekhu
    Participant

    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.

    http://en.wikipedia.org/wiki/Quicksort

You must be logged in to reply to this topic.