

Paul Johnson paul at cogito.org.uk
Thu Oct 22 10:31:55 EDT 2009

This question on StackOverflow asked about how to find the largest 100 
items in a very long list:


I replied that you could do it with something like this (but here taking 
the k smallest to strip out some irrelevant complications):

 >  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 

But of equal practical interest is the space complexity.  The optimum 
What does the function above do?


More information about the Haskell-Cafe mailing list