This is a fundamental algorithm design pattern. Lots of efficient algorithms use sorting as a subroutine since its easier to process data if its in sorted order.
The basic problem in sorting is as follows:
Note
Given an array that contains n elements, your task is to sort the elements in increasing order.
Simple algorithms work in time. A famous algorithm of this sort is bubble sort where elements bubble to their correct spots in the array.
Inversions
An inversion is basically a swap where for indices a, and b, a < b and array[a] > array[b]. Sorting is done when no more inversions are required.
Sorting Algorithms
It is not possible to sort an array faster than time if we need to compare array elements.