Choose the Fastest Sort Part I

To sort the list

A = [ 3 , 5 , 4 , 6 , 12 , 8 , 2 , 1 ] , A = [3,5,4,6,12,8,2,1],

which algorithm is faster?

Insertion Sort Bubble Sort Mergesort

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Karleigh Moore
Mar 22, 2016

Mergesort takes O ( n lg n ) O(n \lg n) time no matter the input. Bubble Sort takes O ( n 2 ) O(n^2) time when the input is not already sorted. Insertion Sort takes O ( n 2 ) O(n^2) when the input is relatively unordered since its average and worst case is O ( n 2 ) O(n^2) . The best case for Insertion Sort is O ( n ) O(n) , but in order to achieve this running time, the input must already be fairly ordered. This input list is not sorted or close to sorted, so Mergesort is the fastest algorithm to sort this input.

Isn't Insertion sort the best option for small data sizes? I assume array of length 8 is small tho.

Prakhar Kanchan - 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...