On Thu, May 14, 2009 at 1:09 PM, gary ng <[email protected]> wrote:

>  Memoization helps though the question would be what happens if I say 'fib
> 10000' or whatever number that exceed the recursion limit. Python has this
> limit though Guido has expressed that he is of no interest in implementing
> TCO. So naturally, I tend not to code in this style but use the 'generator'
> idiom and Memoization still benefits.
>

To answer my own question, 'fib 10000' caused stack overflow. Though it hits
the numeric system limit at around 'fib 1200' which gives '_'. So like the
Ackermann case, stack overflow is a lesser concern.

In general, I would agree with Roger that M. is more important as that
usually is the first real world constraint(exponential computation time) we
encounter for non-trivial problem.

For reference, below is the the Haskell solution :

let fib = 0:1: zipWith (+) fib (tail fib)

I can get fib 150000 before I run out of memory as Haskell now supports big
integer just like Python. A nice thing about the above Haskell solution is
that M. comes free.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to