Re: [OT] Re: Recursive Functions
From: Eric Sosman (Eric.Sosman_at_sun.com)
Date: 10/29/03
- Next message: Default User: "Re: Dynamic arrays"
- Previous message: Dan Pop: "Re: arrow operator"
- In reply to: Marcus Lessard: "Re: [OT] Re: Recursive Functions"
- Next in thread: Glen Herrmannsfeldt: "Re: Recursive Functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Oct 2003 11:39:16 -0500
Marcus Lessard wrote:
>
> "Glen Herrmannsfeldt"
> ...
> >
> > If n is a power of two, such as 2**m, it will square the number m times.
> >
> > I suppose as an example for recursive algorithms it is a little better
> than
> > factorial.
> >
> > -- glen
>
> From a mathematical point of view there is no difference in breaking up the
> computation into a set of squares and then multiplying. What is going on in
> the underlying processing that makes using the squares more efficient than
> just multiplying x by itself n times?
Count the multiplications:
x*x*x*...*x*x*x = x^128
x*x = x^2, x^2*x^2 = x^4, ..., x^64*x^64 = x^128
Which do you think will be faster: 127 multiplications or 7?
-- Eric.Sosman@sun.com
- Next message: Default User: "Re: Dynamic arrays"
- Previous message: Dan Pop: "Re: arrow operator"
- In reply to: Marcus Lessard: "Re: [OT] Re: Recursive Functions"
- Next in thread: Glen Herrmannsfeldt: "Re: Recursive Functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|