Sorting Algorithms


In computer science, a sorting algorithm is 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 (such as search and merge algorithms) that require input data to be in sorted lists. Sorting is also often useful for canonicalizing data and for producing human-readable output.


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.


The most common example we experience every day is sorting clothes or other items on an e-commerce website either by lowest-price to highest, or list by popularity, or some other order.




Types of Sorting Algorithms


Bubble Sort

Insertion Sort

Selection Sort

Quick Sort




Time Complexities of Sorting Algorithms:


Algorithm Best Average Worst
Quick Sort Ω(n log(n)) Θ(n log(n)) O(n^2)
Bubble Sort Ω(n) Θ(n^2) O(n^2)
Merge Sort Ω(n log(n)) Θ(n log(n)) O(n log(n))
Insertion Sort Ω(n) Θ(n^2) O(n^2)
Selection Sort Ω(n^2) Θ(n^2) O(n^2)
Heap Sort Ω(n log(n)) Θ(n log(n)) O(n log(n))
Radix Sort Ω(nk) Θ(nk) O(nk)
Bucket Sort Ω(n+k) Θ(n+k) O(n^2)