An algorithm that puts elements of a list into an order. The most frequently used orders are numerical order and lexicographical order, and either ascending or descending. Efficient sorting is important for optimizing the efficiency of other algorithms that require input data to be in sorted lists. All examples will be ascending order.

  • Keywords for sorting algorithms are Stable, In-place, and Adaptive
  • Comparison-based sorting algorithms are theoretically impossible to optimize beyond

Iterative Sorts

Solve the sorting problem by iteratively processing the entire dataset. Iterative Sorts are generally bad unless the data set is relatively small (we say generally bad because datasets are generally not small) If the dataset is relatively small, they can even perform better than Divide and Conquer Sorts due to being Adaptive (D&C are not) and having far better Auxiliary Space Complexity by all being In-place (D&C are not [QuickSort is technically in place but not really and still has the overhead of recursive calls])

Best CaseAverage CaseWorst CaseStableAdaptiveIn-place
Bubble SortYesYesYes
Cocktail Shaker SortYesYesYes
Insertion SortYesYesYes
Selection SortNoNoYes

Divide and Conquer Sort

Recursively break down the dataset into smaller subproblem, solve each subproblem independently, and then recombine the solutions to achieve a final sorted order.

Best CaseAverage CaseWorst CaseStableAdaptiveIn-place
HeapSortNoNoNo
Merge SortYesNoNo
QuickSortNoNoIn*

Noncomparative

Best CaseAverage CaseWorst CaseStableAdaptiveIn-place
LSD Radix SortYesNoNo