[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:14 Oct 2004 12:34:58 -0000 
Subject:Re: string library question (fwd) 
From:Jonathan L Cunningham 
Volume-ID: 

On Tue, 12 Oct 2004 08:53:07 +0000 (UTC), A.Sloman@cs.bham.ac.uk
wrote:

>Jonathan,
>
>Many thanks for the correction.
>
>I was too hasty!
>
>Have you thought about the implications of your comments for the
>(very nasty) Ackermann function?
>
>I haven't!

Not beyond the obvious -- that tail recursion optimisation can only
eliminate the outer call.

It may be worth commenting that when people think about complexity
of algorithms, they are usually thinking of time complexity (is
it polynomial time, or exponential or whatever?).

There is a corresponding issue with space complexity (how much
memory is needed to run this algorithm).

For real problems, you can sometimes trade space v. time in your
choice of algorithm. For Ackemann's function, you can speed it up
by using "memo functions" as they were called. I can't remember
if it is a standard poplog library or not ... I know it is
certainly a technique I sometimes find useful.

Basically, you "memoise" a function by wrapping it in a procedure
which checks whether it has been previously called on the same
arguments by looking them up in a table (see NEWPROPERTY) and
only calling the function if the result has not been previously
computed (and then, of course, cacheing the result in the property).

Someone might like to try this on Ackermann :-).

Jonathan

-- 
    Use jlc1 at address, not spam.