Recursion or iteration (was Fibonacci series recursion error)

rusi rustompmody at gmail.com
Mon May 2 21:48:25 EDT 2011


On May 3, 2:50 am, harrismh777 <harrismh... at charter.net> wrote:
> The thing about this problem that puzzles me, is why we might consider
> recursion for a possible solution in the first place....

This can be answered directly but a bit lengthily.
Instead let me ask a seemingly unrelated (but actually much the same)
question.

Here are two power functions:

def powI(x,n):
    result = 1
    for i in range(0,n):
        result = result * x
    return result

def powR(x,n): return 1 if (n==0) else (x * powR(x, n-1))

What are their space/time complexities?
Which do you prefer?



More information about the Python-list mailing list