Reputation: 2678
I understand the significance of the in place property of a sorting algorithm.
I know that stability helps in maintaining the relative order, but does the algorithm's stability property affect its performance?
Upvotes: 1
Views: 245
Reputation: 15982
From Wikipedia:
A sorting algorithm is stable if whenever there are two records R and S with the same key, and R appears before S in the original list, then R will always appear before S in the sorted list.
About your questions:
Does the algorithm's stability property affect it's performance?
I think the stability of an algorithm is not related to their efficiency, are two separate concepts.
Stability is a property that a sorting algorithm can have or not depending to it nature, but is like a 'side effect', doesn't impact directly in its performance.
An unstable algorithm can easily be converted to stable by adding an extra index key to compare if the primary keys match.
If your question is like How implement a stable sorting algorithm, then stability probably will impact since it is an extra requirement to comply.
Why is it necessary?
You can read about the benefits of stable algorithm in this question.
Upvotes: 1