时间是什么.NET List.sort的复杂性()复杂性、时间、List、NET

2023-09-03 16:08:51 作者:荒了青春╮失了流年

什么是时间的C#的复杂性名单,其中,T> .Sort()

What is time complexity of C#'s List<T>.Sort()

我想这是O(N)

但之后我搜索了很多,我没有得到任何准确的结果。

But after I searched a lot, I didn't get any accurate result.

推荐答案

http://msdn.microsoft.com/en-us/library/b0zbh7b6.aspx

此方法使用的Array.Sort,它采用了快速排序算法。此实现执行不稳定排序;也就是说,如果两个元素是相等的,它们的顺序可能不是preserved。与此相反,一个稳定的排序preserves中等于元素的顺序

This method uses Array.Sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.

在平均,这种方法是为O(n log n)的操作,其中n是计数;在最坏的情况下,它是一个为O​​(n ^ 2)操作

On average, this method is an O(n log n) operation, where n is Count; in the worst case it is an O(n ^ 2) operation.