Jules, On Jun 23, 2009, at 2:25 AM, Jules wrote:
> Let N be the total number of elements in your collection (e.g. > 1,000,000), and n the number of elements that you want to take out of > this collection (e.g 10). > > By sorting the collection of N elements you spend N log N time. By > repeatedly adding an to the small collection and removing the minimum > you spend N log n time (if you have a good sorted collection that > takes log n time to insert). > > The algorithm spelled out in imperative pseudocode is: > > def top_n(n,coll) > let result = new SortedCollection(take n from coll) > for x in (drop n from coll): > result.add(x) > result.deleteMinimum() // adding 1 element and removing 1 keeps > the result collection at size n > return result > > Hope this helps, Yes, this explains it. :) Thanks! — Daniel Lyons --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---