[Haskell-cafe] Producing MinimumValue

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Jul 19 14:26:39 EDT 2007

On 19/07/07, Steve Schafer <steve at fenestra.com> wrote:
> On Thu, 19 Jul 2007 10:55:19 -0700 (PDT), you wrote:
> >The question suggests to use some functions defined in the section, and one
> >of them is iSort.
> Aha. Well, that one certainly lends itself better to this particular
> proplen than either map or filter.
> >minimumValue :: [Int] -> Int
> >minimumValue ns = head (iSort ns)
> If I were going to use a sort, then yes, that's the way I would do it.
> Of course, sorting isn't the best way to solve the problem, as sorting
> will always be at least O(n * log n), whereas a more straightforward
> algorithm would be O(n).

Actually, since Haskell is lazy and only the first element is required
for minimumValue, the above algorithm should be O(n).

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list