Hi Everybody,
I wrote the simple function for computing the number of binary-search-trees
that can be formed from a sequence of numbers from 1 to N using
memoization. I get a stack-overflow for values more than N of 196. Can
anybody help me in figuring out how to fix this?
Thanks,
Sunil.
(defn num-trees [n]
(let [modulo 100000007
trunc #(mod % modulo)
mult-m (comp trunc *)
add-m (comp trunc +)
h (fn [mf l]
(if (<= l 1) 1
(trunc (reduce add-m 0
(map #(mult-m (mf mf (- l % 1)) (mf mf %))
(range l))))))
mf (memoize h)]
(mf mf n)))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.