What is the benefit for a sort algorithm to be stable?

It enables your sort to ‘chain’ through multiple conditions.

Say you have a table with first and last names in random order. If you sort by first name, and then by last name, the stable sorting algorithm will ensure people with the same last name are sorted by first name.

For example:

  • Smith, Alfred
  • Smith, Zed

Will be guaranteed to be in the correct order.

Leave a Comment