[Haskell-beginners] Removing the biggest element from a list -
maybe slow?
Daniel Fischer
daniel.is.fischer at web.de
Mon May 24 10:04:37 EDT 2010
On Monday 24 May 2010 15:49:35, matthew coolbeth wrote:
> It is linear time, implemented roughly as below
>
> delete z [] = []
> delete z (x:xs) = if x=z then delete z xs else x:(delete z xs)
>
delete only deletes the first occurrence, so it's equivalent to
delete z (x:xs)
| x == z = xs
| otherwise = x : delete z xs
delete _ [] = []
, it's O(index of z) thus.
More information about the Beginners
mailing list