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

前端 未结 5 2278
面向向阳花
面向向阳花 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:13

    From the documentation:

    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.

    This is because it uses Quicksort. While this is typically O(n log n), as mentioned on Wikipedia, "Quicksort is often faster in practice than other O(n log n) algorithms"

提交回复
热议问题