A sorting algorithm is called stable if it preserves the rel
A sorting algorithm is called stable if it preserves the relative order of any two equal elements in its input. That is, if a[i] - a[j] with i
Solution
1) Merge sort, Insertion sort and bubble sort are stable. Where as heap sort and quick sort are not stable.
2) Stability is very important in certain cases. Lets say we are supposed to sort a list of persons with last names and then by first names. Here we should first sort the list by first names (might be unstable sort) then we should use a stable sort by the last names.
![A sorting algorithm is called stable if it preserves the relative order of any two equal elements in its input. That is, if a[i] - a[j] with i Solution1) Merge A sorting algorithm is called stable if it preserves the relative order of any two equal elements in its input. That is, if a[i] - a[j] with i Solution1) Merge](/WebImages/42/a-sorting-algorithm-is-called-stable-if-it-preserves-the-rel-1131901-1761604885-0.webp)