Is there anyway to optimise this recursive algorithm so I don't get an OutOfMemory error?

Printable View