What is time complexity of .NET List.sort()

前端 未结 5 2418
面向向阳花
面向向阳花 2021-02-19 05:37

What is time complexity of C#\'s List.Sort()

I guess it\'s o(N)

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

5条回答
  •  轮回少年
    2021-02-19 06:38

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

    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.

    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.

提交回复
热议问题