Uses a FOR or WHILE loop. It's based on data external to the data you're working with
Because you don't pass the function back into itself, you don't need to store any data in a call stack. So you just play with the data in a single call to a function.
Calls a function on itself over and over again. You take the data you're working with and continually feed it back in until you get the desired result
Often uses stacks (the call stack) When you use recursion, you have something of the form
def function(data) … return function(altered data)
So what happens, is that your function is pushing off the solution, and pushing it off, and pushing it off, until it reaches the final step of the recursion. Then it solves that problem, passes the answer into the previous level, passes that into the previous level, and so on.
ex. Find n!
We take n(n-1)…1
So the recursion is
def fact(n): if n == 0: return 1 else: return n*mult(n-1)
So applying fact(3) will do: 3 -> 3 * fact(2) -> 3 *(2 * fact(1)) -> 3(2(1 * fact(0))) -> 3(2(1(1))) -> 3(2(1)) -> 3(2) -> 6
Note then, that we need to hold on to all of the previous steps of the recursion we haven't compeleted yet; they're waiting for the later steps to finish — when we're computing fact(1), we still need to know that after we do that, we have to pass the data back into fact(2), where it will be multiplied by 2, and then passed into fact(3)
-In order for your computer to deal with this, each time the function is called, it needs to store the current RETURN procedure, along with the previous ones