top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can we insure stability in sorting algorithms?

+1 vote
364 views
How can we insure stability in sorting algorithms?
posted Apr 8, 2014 by Vishvachi Tiwari

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input unsorted array. Some sorting algorithms are stable by nature like Insertion sort, Merge Sort, Bubble Sort, etc. And some sorting algorithms are not, like Heap Sort, Quick Sort, etc.

However, any given sorting algo which is not stable can be modified to be stable. There can be sorting algo specific ways to make it stable, but in general, any comparison based sorting algorithm which is not stable by nature can be modified to be stable by changing the key comparison operation so that the comparison of two keys considers position as a factor for objects with equal keys.More Info

answer Apr 8, 2014 by Atul Mishra
Similar Questions
+1 vote

Is there any explanation available of the different merits and drawbacks of the diff algorithms that Git supports?

I'm not satisfied with the default diff but have enough processing power for a slower algorithm that might produce diffs that better show the intention of the edit.

...