Sorting Stability
A sorting algorithm is stable if equal-key elements retain their relative order after sorting. Stability matters when records contain multiple fields and sorting is performed in stages. For example, if employees are first sorted by name and then stably sorted by department, employees within each department retain their name ordering.
Stable sorting preserves relative order among equal keys.
Useful for multi-stage sorting.
Merge Sort is commonly stable.
Standard Heap Sort is not stable.
Stability is also useful when records contain an implicit prior ordering.