Overview

A sorting algorithm is an algorithm that puts elements of a list in a certain order (thus sorting the list). The most frequently used orders are numerical order for lists of numbers and lexicographical order for lists of strings.

To put it more formally, the output generally has to fulfill two conditions:
  • The output is in nondecreasing order
  • The output is a permutation of the input
Or, to put it simply, when running a sorting algorithm we expect an output that contains all the elements originally present in the input arranged in such a way that the smallest element (according to the operation used to sort the list) is in the leftmost place, with every element following being either bigger or equal to its predecessor.

Sorting algorithms can generally be classified into three distinct categories:
  • Comparison sorts
  • Non-comparison sorts
  • Others
On this page you can find many implementations for every category. If you need a visualization for a certain algorithm, just use the search function to find it quickly.

Search


A comparison sort is a type of sorting algorithm that only reads the list elements through a single abstract comparison operation (often a "less than or equal to" operator or a three-way comparison) that determines which of two elements should occur first in the final sorted list.