Hi

> > main n = print . sum . map read . take n . reverse . lines =<< getContents
>
> Could someone describe succinctly how to compute the space complexity of
> this program, if there are m lines of input and m >> n? Many thanks. --PR

The space complexity is the size of the file - i.e. of size m. reverse
will buffer up all the lines before it gives any back, which is a well
known property of reverse. You could rewrite (take n . reverse) as a
function that only requires n lines of buffer.

Thanks

Neil
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to