[Haskell-cafe] Getting highest sum of list elements with Map

Yitzchak Gale gale at sefer.org
Wed Aug 5 06:53:48 EDT 2009


Hi Gwern,

gwern0 wrote:
> ...efficiency is an issue.

Here are a few efficiency issues that I noticed in your algorithm
after a quick look (none of these have to do with Haskell really):

o ranks sorts the entire set, then discards all but the maximum.
  It would be better to use maximum or maximumBy.
  If you are worried about the empty set, check that separately.

o You recompute the same rank value repeatedly for every word
  in each sentence. Use a "let" clause in your list comprehension
  to do it only once per sentence.

o approximation rescans the entire corpus after discarding each
  word. Try to think of a way to recompute only those sentences
  that contained the word.

Hope this helps,
Yitz


More information about the Haskell-Cafe mailing list