I know to prove instability, we can simply provide a counter-example. But is there a general way to prove that a sorting algorithm is stable? Could you please tell a general method and then show an example perhaps on insertion or merge sort.
Asked
Active
Viewed 1,444 times
4
-
1Note that, in general, proof is a creative process and one can't usually give general methods. But it's possible that stability of sorting algorithms is a specific enough domain that there are specific techniques. – David Richerby Oct 09 '17 at 13:42
-
1One proof technique which comes to mind is: show that if $A[i] = A[j]$ for some $i < j$, then the elements $A[i],A[j]$ end up in the correct order in the sorted array. – Yuval Filmus Oct 09 '17 at 14:02
-
Making @YuvalFilmus's idea a bit more concrete, if the algorithm consists of a number of phases, it would suffice to show that each phase preserves the order of a pair of equal values. – j_random_hacker Oct 09 '17 at 16:13
-
1@YuvalFilmus That's the claim, not a proof technique. – Raphael Oct 09 '17 at 16:24
-
1@j_random_hacker's proposal in formal terms: perform an induction over the steps of the algorithm. – Raphael Oct 09 '17 at 16:25
-
Is it a comparison-based sorting algorithm? – D.W. Oct 10 '17 at 03:42
-
https://cs.stackexchange.com/q/51489/755 – D.W. Oct 10 '17 at 03:46