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.
Insertion sort or selection sort are both typically faster for small arrays (i.e., fewer than 10-20 elements).
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.
Insertion Sort is a good choice for "small" data sets.
2.1 Insertion Sort It is an efficient algorithm for sorting a small number of elements.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With