Thanks David. Could you recommend any other types of search, or a different algorithm entirely, which might give me the same output in a sequence?
On Fri, Jun 8, 2012 at 1:29 PM, David Powell <djpow...@djpowell.net> wrote: > > (dorun (take 20000000 (add-layer))) >>> >> take holds on to the head, because that is what it returns. Try changing >> take to drop. >> > > Take is lazy though, and dorun should drop the head, so that shouldn't be > a problem. > > > The problem here is not an holding onto the head issue. Lots of memory is > being used, because the algorithm requires lots of memory. > A breadth first search takes each level in the tree and makes a new level > by adding 3 nodes for each existing node. So the original level has to > exist in memory at some point in order to do that. > > When you get to the 2millionth element (not even the 20millionth element), > the strings are already 13 characters long. To add an extra character to > each of those, then it will use 3^13 strings * 13 characters * (2 bytes per > character + some overhead) - this is at least 41mb. > By the 14th character, you are going to need at least 133mb. > By the 15th character, you are going to need at least 430mb. > > This is just the cost of using a breadth-first search. > > Either use a different type of search; get more memory and up the heap > size; or make a compact numeric of the strings, and map them back to > readable string form as a post-processing step. > -- 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