Time and space costs for the eight sorts in this unit, with whether each one is stable and whether it sorts in place. Click a column heading to sort the table, and click an algorithm's name to open its interactive lab.
| Time | ||||||||
|---|---|---|---|---|---|---|---|---|
| Algorithm | Best | Average | Worst | Extra space | Stable | In place | Adaptive | Good to know |
Stable: values that compare equal keep their original order. This matters when you sort by one field after another, such as by name and then by grade.
In place: the sort rearranges the array itself, using only O(1) or O(log n) extra memory, instead of copying into a second array.
Adaptive: the sort runs faster when the input is already partly in order.
For radix sort: d is the number of digits in the largest key, and b is the base (10 for decimal digits).