What does it mean that a sorting algorithm is stable?
Items with equal keys keep their original order.
- It never crashes on large lists
- It always takes the same time
- Items with equal keys keep their original order ✔
Why: Say you sort students by grade. A stable sort keeps students with the same grade in the order they were already in, such as alphabetical. That lets you sort by one field, then another, and keep both orders.
Huh, didn't know that: Python's sorted() and list.sort() are guaranteed stable and use Timsort, which takes advantage of order already in the data.
My sorting algorithm is very stable. It has a good job and a nice house.
References
Answer: Items with equal keys keep their original order. Say you sort students by grade. A stable sort keeps students with the same grade in the order they were already in, such as alphabetical. That lets you sort by one field, then another, and keep both orders.
- Python docs: Sorting Techniques docs.python.org/3/howto/sorting.html
when multiple records have the same key, their original order is preserved
Checked 2026-10-11.
Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.
More stuff everyone should know
That's stuff everyone should know.