Sorting


The sorting problem is a mapping from to , where:

  • and are both n length real vectors (lists and/or arrays).
  • is a permutation of (different ordering).
  • for all .

It is the problem or reordering items of an array in a certain order.

Sorting methods

Stability

A stable sort guarantee to preserve the ordering from a first sort, where the second sort finds the records to be equal.

An unstable sort does not make this guarantee. Unstable methods can all be made stable.

Examples

  • Stable methods:
    • Merge sort and variants.
    • Variants of bubble sort.
    • Insertion sort and variants.
    • Variants on bucket sort.
      • Counting sort and variants.
    • Timsort (merge/insertion variant, Python).

Comparison of Sorting Algorithms

Screenshot 2022-10-24 at 17.11.12