
14 Oct
2007
14 Oct
'07
9:22 p.m.
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