排序小整数数组的最佳排序算法是什么? [英] What is the best sorting algorithm to sort an array of small integers?
本文介绍了排序小整数数组的最佳排序算法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据问题标题,如果数组的长度为奇数且数组元素的编号为1 - 10.
As per question title, if the array is of an odd length and the array elements are numbered 1 - 10.
示例,
3 6 8 1 3 7 7 9 4 1
3 6 8 1 3 7 7 9 4 1
我是想使用 heapsort ?由于它是一个数组,合并排序和插入排序需要转移,并且效率不高。
I was thinking of using heapsort? Since it is an array, merge sort and insertion sort requires shifting, and would not be so efficient.
推荐答案
数组元素的数字是1 - 10.
the array elements are number from 1 - 10.
有了这个限制,计数排序将比任何通用排序算法更有效 - 它是O( n)
With this restriction, counting sort will be far more efficient than any general purpose sorting algorithm - it's O(n)
这篇关于排序小整数数组的最佳排序算法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文