Equivalent items don’t ‘cross over’ when being stably sorted.
On the other hand...
Sorting instability can be really annoying! Wanted students listed alphabetically by section.
In Java, Arrays.sort(someArray) uses:
Mergesort (specifically the TimSort variant) if someArray consists of Objects.
Quicksort if someArray consists of primitives.
Sorting is a foundational problem.
Obviously useful for putting things in order.
But can also be used to solve other tasks, sometimes in non-trivial ways.
Sorting improves duplicate findings from a naive N^2 to N log N.
Sorting improves 3SUM from a naive N^3 to N^2.
There are many ways to sort an array, each with its own interesting tradeoffs and algorithmic features.
Today we’ll discuss the fundamental nature of the sorting problem itself: How hard is it to sort?