[Haskell-cafe] Time and space complexity of "take k . sort"

Paul Johnson paul at cogito.org.uk
Thu Oct 22 11:57:44 EDT 2009


On 22/10/09 15:31, Paul Johnson wrote:
>
> >  takeLargest k = take k . sort
>
> Because "sort" is lazily evaluated this only does enough sorting to 
> find the first k elements.  I guess the complexity is something like 
> O(n*k*log(k)).
>
Correction: O(n*log(k))


More information about the Haskell-Cafe mailing list