Iteration over recursion?

Tim Peters tim.peters at gmail.com
Wed Jun 21 21:44:34 EDT 2006


[MTD <marc.t.davies at gmail.com>]
> I've been testing my recursive function against your iterative
> function, and yours is generally a quite steady 50% faster on
> factorizing 2**n +/- 1 for  0 < n < 60.

If you're still not skipping multiples of 3, that should account for most of it.

> I think that, for a challenge, I'll try to make a recursive function that
> matche or beats the iterative function -- it's worth the experiment!

Don't stop on that one before you succeed ;-)  Provided you make no
more than one recursive call per factor, you can't make more than
log(n, 2) recursive calls in total, and _typically_ far fewer than
that.  IOW, the number of recursive calls should generally be trivial,
and factoring 2**n will be the worst case.



More information about the Python-list mailing list