retagged by
1,795 views

1 Answer

5 votes
5 votes

The sort performance is always highly dependent on your data and scenario. It's hard to say one to be the worst always.

Insertion Sort [Best: O(N), Worst:O(N^2)]

Start with a sorted list of 1 element on the left, and N-1 unsorted items on the right. Take the first unsorted item (element #2) and insert it into the sorted list, moving elements as necessary. We now have a sorted list of size 2, and N -2 unsorted elements. Repeat for all elements.

Heapsort [Best/Avg/Worst: O(N lg N)]

Add all items into a heap. Pop the largest item from the heap and insert it at the end (final position). Repeat for all items.

Bubble Sort [Best: O(n), Worst:O(N^2)]

Starting on the left, compare adjacent items and keep “bubbling” the larger one to the right (it’s in its final place). Bubble sort the remaining N -1 items.

Quicksort [Best: O(N lg N), Avg: O(N lg N), Worst:O(N^2)]

Answer:

Related questions

0 votes
0 votes
2 answers
2
_Madhuri asked Oct 9, 2021
664 views
The complexity of comparison based sorting algorithm is (nlogn) .How?
1 votes
1 votes
1 answer
4
iarnav asked May 4, 2019
850 views
I’ve seen this wikipedia article – https://en.wikipedia.org/wiki/Comparison_sortAlso see this link – https://gateoverflow.in/32948/minimum-number-of-comparisonshttp...