简体   繁体   English

计数排序的下限为 O(n)

[英]Counting Sort has a lower bound of O(n)

The running time of counting sort is Θ (n+k).计数排序的运行时间为Θ(n+k)。 If k=O(n), the algorithm is O(n).如果 k=O(n),则算法为 O(n)。 The k represents the range of the input elements. k 表示输入元素的范围。 Can I say that the Counting sort has a lower bound of O(n) because the algorithm takes O(n) time to compute a problem and that the lower bound of O(n) shows that there is no hope of solving a specific computation problem in time better than Ω(n)??我可以说计数排序的下限为 O(n),因为该算法需要 O(n) 时间来计算问题,并且 O(n) 的下限表明没有希望解决特定的计算比Ω(n)更好的时间问题??

Well yes since T(n,k) = Theta(n+k) then T(n,k) = Omega(n+k).是的,因为 T(n,k) = Theta(n+k) 然后 T(n,k) = Omega(n+k)。 Since k is nonnegative we know that n + k = Omega(n) and so T(n, k) = Omega(n) as required.由于 k 是非负的,我们知道 n + k = Omega(n) ,因此 T(n, k) = Omega(n) 是必需的。

Another perspective on why the lower bound is indeed Ω(n): if you want to sort an array of n elements, you need to at least look at all the array elements.关于为什么下限确实是 Ω(n) 的另一种观点:如果要对包含 n 个元素的数组进行排序,则至少需要查看所有数组元素。 If you don't, you can't form a sorted list of all the elements of the array because you won't know what those array elements are.如果不这样做,则无法形成数组所有元素的排序列表,因为您将不知道这些数组元素是什么。 :-) :-)

That gives an immediate Ω(n) lower bound for sorting any sequence of n elements, unless you can read multiple elements of the sequence at once (say, using parallelism or if the array elements are so small that you can read several with a single machine instruction.)这为排序任何 n 个元素的序列提供了一个直接的 Ω(n) 下限,除非您可以一次读取序列的多个元素(例如,使用并行性,或者如果数组元素太小以至于您可以使用单个元素读取多个元素)机器指令。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM