sorting

References

Summary

Iterative

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.

Recursive

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

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