A Sorting Algorithm is used to rearrange a given array or list elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of element in the respective data structure.
For example: The below list (Array) of numbers is sorted in increasing order of their values. That is, the number with lesser value will be placed first than the number with higher value.
[5, 3, 1, 4, 2] ===> [1, 2, 3, 4, 5]