Sorting

Sorting means ordering the elements of a collection according to a criterion. Simple algorithms (bubble sort, insertion sort) are O(n²), whereas efficient sorts (merge sort, quicksort) are O(n log n). In practice, you use the language's built-in sort, such as sorted() in Python, which is stable.

Example

sorted([3, 1, 2], reverse=True)  # [3, 2, 1]

Related concepts

The whole glossary