【发布时间】:2013-11-01 06:10:42
【问题描述】:
我被这个问题困住了(2 周)。知道如何处理它吗?。
令 L 是 n 个不同整数的列表,假设 L 的 x 的元素在 [1,750] 范围内。设计一个线性排序算法对L的元素进行排序
我已经尝试过插入排序。但我不确定我的方法是否正确:
Construct an array of bits. Initialize them to zero.
Read the input, for each value you see set the respective bit in the array to 1.
Scan the array, for each bit set, output the respective value.
复杂度 => O(2n) = O(n)
【问题讨论】:
-
嗯,你的方法是什么?
-
@ChristianTernus 他说他尝试使用插入排序,fwiw。
-
是的,但这与显示代码或至少是伪代码不同。
-
在 wc,我认为不可能在 O(n) 处排序。
-
我编辑了问题
标签: algorithm sorting time-complexity