Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6872377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:55:12+00:00 2026-05-27T03:55:12+00:00

The Heap Sort sorting algorithm seems to have a worst case complexity of O(nlogn),

  • 0

The Heap Sort sorting algorithm seems to have a worst case complexity of O(nlogn), and uses O(1) space for the sorting operation.

This seems better than most sorting algorithms. Then, why wouldn’t one use Heap Sort always as a sorting algorithm (and why do folks use sorting mechanisms like Merge sort or Quick sort)?

Also, I have seen people use the term ‘instability’ with Heap sort. What does that imply?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:55:13+00:00Added an answer on May 27, 2026 at 3:55 am

    A stable sort maintains the relative order of items that have the same key. For example, imagine your data set contains records with an employee id and a name. The initial order is:

    1, Jim
    2, George
    3, Jim
    4, Sally
    5, George
    

    You want to sort by name. A stable sort will arrange the items in this order:

    2, George
    5, George
    1, Jim
    3, Jim
    4, Sally
    

    Note that the duplicate records for “George” are in the same relative order as they were in the initial list. Same with the two “Jim” records.

    An unstable sort might arrange the items like this:

    5, George
    2, George
    1, Jim
    3, Jim
    4, Sally
    

    Heapsort is not stable because operations on the heap can change the relative order of equal items. Not all Quicksort implementations are stable. It depends on how you implement the partitioning.

    Although Heapsort has a worst case complexity of O(n log(n)), that doesn’t tell the whole story. In real-world implementation, there are constant factors that the theoretical analysis doesn’t take into account. In the case of Heapsort vs. Quicksort, it turns out that there are ways (median of 5, for example) to make Quicksort’s worst cases very rare indeed. Also, maintaining a heap is not free.

    Given an array with a normal distribution, Quicksort and Heapsort will both run in O(n log(n)). But Quicksort will execute faster because its constant factors are smaller than the constant factors for Heapsort. To put it simply, partitioning is faster than maintaining the heap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Heap Sort has a worst case complexity of O(nlogn) while Quicksort has O(n^2) .
Suppose I have, Heap Sort method which its complexity time is O(nlogn). When I
Heap - Sort Algorithm The problem I am having is this, this algorithms n
std::sort() uses the Introsort algorithm that switches between quick & heap sort depending upon
I am trying to write a generic Heap Sort algorithm. I get the following
I was reading sorting method which include bubble sort, selection sort, merge sort, heap
I'm trying to implement a array based Heap Sort, its sorting the first few
I am reviewing the Heap Sort Algorithm . I am wondering why it is
Both quicksort and heapsort do in-place sorting. Which is better? What are the applications
I'm kind of stuck with my heap sort here in php: <?php function heapSort($a,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.