Sorting is an operation in computer science via which data is being arranged in an ordered sequence. There are lots of efficient algorithms are already present to perform sorting operation which we are going to discuss here.
Some of the most used sorting algorithms are as follows:
1) Bubble Sort
2) Insertion Sort
3) Merge Sort
4) Selection Sort
5) Quick Sort
6) Heap Sort
Comparison of various Sorting algorithms in terms of time complexity for best and worst case:
Sorting Algorithm | Time Complexity |
Bubble Sort | Best Case: O(n) . This occurs when array is already sorted. Worst Case: O(n*n). This occurs when array is reverse sorted. |
Insertion Sort | Best Case: O(n) . This occurs when array is already sorted. Worst Case: O(n*n). This occurs when array is reverse sorted. |
Selection Sort | Best and Worst Case: O(n*n). Not dependent on data distribution. |
Merge Sort | Best and Worst Case: O(nLogn). Not dependent on data distribution. |
Quick Sort | Best Case: O(nLogn) . This occurs data distribution is random. Worst Case: O(n*n). This occurs when array is already sorted. |
Heap Sort | Best and Worst Case: O(nLogn). Not dependent on data distribution. |
As we can see, every sorting algorithm has some pros and cons. Hence, for choosing sorting algorithm type of data and size of data needs to be considered. All of these we will discuss in specific search algorithm explanations.