Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornell!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!udel!gatech!rutgers!njitgw.njit.edu!hertz.njit.edu!kxn3796
From: kxn3796@hertz.njit.edu (Ken Nakata)
Subject: Re: factorial algorithm
Message-ID: <1994Nov8.173643.17118@njitgw.njit.edu>
Sender: news@njit.edu
Nntp-Posting-Host: hertz.njit.edu
Organization: New Jersey Institute of Technology, Newark, New Jersey
References: <39l7er$q02@wsiserv.informatik.uni-tuebingen.de>
Date: Tue, 8 Nov 1994 17:36:43 GMT
Lines: 35

In article <39l7er$q02@wsiserv.informatik.uni-tuebingen.de>,
Hannes Haug <haugha@informatik.uni-tuebingen.de> wrote:
>The factorial algorithm apears quite often in postings and text books.
>But it always seems to be a rather slow implementation.

[the first function to calculate factorial deleted]

>It computes 10! this way:
>  ((((((((10*9)*8)*7)*6)*5)*4)*3)*2)*1
>
>But that's the wrong direction. This one is faster:

[the second one]

>It computes 10! this way:
>  ((((((((1*2)*3)*4)*5)*6)*7)*8)*9)*10
>
>We can do even better with the last one. It is a divide-and-conquer algorithm.
>It's not the fastest algorithm and may run out of space. But it's simple.

[the last one]

>It computes 10! this way:
>  (((1*2)*3)*(4*5))*(((6*7)*8)*(9*10))

I don't see the point.  It seems to me that each algorithm performs
exactly the same number of multiply operations (9 times in the
example).  Why should the last algorithm be faster than the first two?
Would you mind enlightening me up?

Thanks in advance.

Ken Nakata
-- 
Music is the best                                         -- Frank Zappa
