Skip to main content

Stable vs Unstable Sorting

Learn Stable vs Unstable Sorting (Sorting, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

What Does "Stable" Mean? A sort is STABLE if two elements with EQUAL keys keep their original relative order after sorting. It only matters when sorting by one field while other data is attached - sorting by a single field of unique values makes stability invisible. Stable: Merge Sort, Insertion Sort, Bubble Sort, Counting Sort. Not stable (by default): Quick Sort, Heap Sort, Selection Sort.

More lessons in Sorting