gpt4 book ai didi

c# - .NET List.sort() 的时间复杂度是多少

转载 作者:可可西里 更新时间:2023-11-01 08:16:01 29 4
gpt4 key购买 nike

C# 的 List<T>.Sort() 的时间复杂度是多少?

我猜是o(N)

但是我找了很多,都没有得到准确的结果。

最佳答案

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.

关于c# - .NET List.sort() 的时间复杂度是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9612167/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com