Comparison of Sorting methods in Data Structures

Here we will see some sorting methods. There are 200+ sorting techniques. We will see few of them. Some sorting techniques are comparison based sort, some are non-comparison based sorting technique.

Comparison Based Soring techniques are bubble sort, selection sort, insertion sort, Merge sort, quicksort, heap sort etc. These techniques are considered as comparison based sort because in these techniques the values are compared, and placed into sorted position in ifferent phases. Here we will see time complexity of these techniques.

Analysis TypeBubble SortSelection SortInsertion SortMerge SortQuick SortHeap Sort
Best CaseO(n2)O(n2)O(n)O(log n)O(log n)O(logn)
Average CaseO(n2)O(n2)O(n2)O(log n)O(log n)O(log n)
Worst CaseO(n2)O(n2)O(n2)O(log n)O(n2)O(log n)

some sorting algorithms are non-comparison based algorithm. Some of them are Radix sort, Bucket sort, count sort. These are non-comparison based sort because here two elements are not compared while sorting. The techniques are slightly different. Now we will see the difference between them based on different type of analysis.

Analysis TypeRadix Sort (k is maximum digit)Counting Sort (k is size of count array)Bucket Sort (k is number of buckets)
Best CaseO(nk)O(n + k)O(n + k)
Average CaseO(nk)O(n + k)O(n + k)
Worst CaseO(nk)O(n + k)O(n2)

Sorting techniques can also be compared using some other parameters. Some sorting algorithms are in-place sorting algorithms, and some are out-place sorting algorithms. Those algorithms, that does not require any extra space is called in-place sorting algorithm. Such as quicksort, heapsort algorithms are in-place. But merge sort is out-place sorting technique.

Some algorithms are online and some are offline. If the algorithm accepts new element while the sorting process is going on, that is called the online sorting algorithm. From the above mentioned techniques, the insertion sort is online sorting technique.

Updated on: 27-Aug-2019

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started