Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best sorting algorithm to sort an array of small integers?

Tags:

As per question title, if the array is of an odd length and the array elements are numbered 1 - 10.

Example,

3 6 8 1 3 7 7 9 4 1

I was thinking of using heapsort? Since it is an array, merge sort and insertion sort requires shifting, and would not be so efficient.

like image 539
user236501 Avatar asked Sep 29 '11 09:09

user236501


People also ask

Which sorting algorithm is best for small array?

Insertion sort or selection sort are both typically faster for small arrays (i.e., fewer than 10-20 elements).

What is the best sorting algorithm for array?

Quicksort. Quicksort is generally thought of as the most efficient 'general' sorting algorithm, where nothing is known about the inputs to the array, and it's more efficient than insertion sort on large lists.

Which sort is best for small data sets?

Insertion Sort is a good choice for "small" data sets.

Is an efficient sorting algorithm for smaller input array?

2.1 Insertion Sort It is an efficient algorithm for sorting a small number of elements.


1 Answers

the array elements are number from 1 - 10.

With this restriction, counting sort will be far more efficient than any general purpose sorting algorithm - it's O(n)

like image 164
Michael Borgwardt Avatar answered Oct 19 '22 06:10

Michael Borgwardt