Re: (very) slow recursive function
- From: "Arjen Markus" <arjen.markus@xxxxxxxxxx>
- Date: 30 Oct 2006 02:44:41 -0800
Actually, the code as written will be quadratic in the order of the
Legendre polynom:
To compute Ln, you need Ln-1 and Ln-2. The code will do this by
computing Ln-1 and
Ln-2 separately. Ln-1 is computed by computing Ln-2 and Ln-3, whereas
the other term
is computed by computing Ln-3 and Ln-4 and so on!
In other words: a lot of work is being done at least twice.
You can (of course) examine this by writing at the start of the
function what its
arguments are.
Function calls are slightly slower than inline code, but the real pain
is in evaluating
the same thing over and over again: O(N**2) instead of O(N).
Regards,
Arjen
.
- References:
- (very) slow recursive function
- From: Ralf Schaa
- Re: (very) slow recursive function
- From: Louis Krupp
- (very) slow recursive function
- Prev by Date: Re: Keywords: UPCASE, downcase or Capitalized?
- Next by Date: Re: IEEE intrinsic modules
- Previous by thread: Re: (very) slow recursive function
- Next by thread: Re: (very) slow recursive function
- Index(es):