Skip to interview prep
Apexed

36. What does it mean for a sort to be stable, and why does it matter?

EasySorting

Technical
Show model answer

A stable sort keeps equal elements in their original relative order. It matters when sorting by multiple keys: sort by the secondary key first, then stably by the primary key. Merge sort, insertion sort and Timsort are stable; quicksort and heap sort usually are not.

What does it mean for a sort to be stable, and why does it matter — Data structures & algorithms interview question — Apexed