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

前端 未结 1 747
不思量自难忘°
不思量自难忘° 2021-02-12 08:36

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:04

    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)
提交回复
热议问题