What is the time complexity of Linq OrderBy().ThenBy() method sequence?

前端 未结 1 1766
有刺的猬
有刺的猬 2021-02-12 08:40

I am using Linq and Lambda Operations in my projects and I needed to sort a List according to two properties of a class. Therefore, I used OrderBy().ThenBy() methods as below:

相关标签:
1条回答
  • 2021-02-12 09:00

    The LINQ OrderBy(...).ThenBy(...)...ThenBy(...) method chain form a single sort operation by multiple sort keys (using multi key comparer).

    Thus, regardless of how many ThenBy(Descending) methods do you include in the chain, the time complexity of the sort operation stays the typical for QuickSort O(N*logN) average / O(N2) worst case. Of course more keys you add, comparing two objects will take more time, but the complexity of the sort operation would not change.

    0 讨论(0)
提交回复
热议问题